Skip to main content
added info about static method and non static property
Source Link
ghispi
  • 136
  • 1
  • 6

Probably the proper way would be to pass it via constructor as this would allow you to choose which driver phpFastCache() should without interfering with your class. And thats commonly referred as dependency injection. You have to type hint on the phpFastCache() returned instance interface which is phpfastcache_driver. This gives you two things, you can easily change underlying caching mechanism and still lock only to the instances that you know that implement methods you use in your class.

Then the constructor would look like this:

public function __construct(phpfastcache_driver $cache)
{
  $this->cache = $cache;
}

And the initialisation of the class as follows:

$myCache = new Cache(phpFastCache('files'));

or

$myCache = new Cache(phpFastCache('memcached'));

or whatever storage engine phpFastCache supports.

Edit: I've noticed that you have static methods which do access non static property, you can not do that. Remove static from them.

Probably the proper way would be to pass it via constructor as this would allow you to choose which driver phpFastCache() should without interfering with your class. And thats commonly referred as dependency injection. You have to type hint on the phpFastCache() returned instance interface which is phpfastcache_driver. This gives you two things, you can easily change underlying caching mechanism and still lock only to the instances that you know that implement methods you use in your class.

Then the constructor would look like this:

public function __construct(phpfastcache_driver $cache)
{
  $this->cache = $cache;
}

And the initialisation of the class as follows:

$myCache = new Cache(phpFastCache('files'));

or

$myCache = new Cache(phpFastCache('memcached'));

or whatever storage engine phpFastCache supports.

Probably the proper way would be to pass it via constructor as this would allow you to choose which driver phpFastCache() should without interfering with your class. And thats commonly referred as dependency injection. You have to type hint on the phpFastCache() returned instance interface which is phpfastcache_driver. This gives you two things, you can easily change underlying caching mechanism and still lock only to the instances that you know that implement methods you use in your class.

Then the constructor would look like this:

public function __construct(phpfastcache_driver $cache)
{
  $this->cache = $cache;
}

And the initialisation of the class as follows:

$myCache = new Cache(phpFastCache('files'));

or

$myCache = new Cache(phpFastCache('memcached'));

or whatever storage engine phpFastCache supports.

Edit: I've noticed that you have static methods which do access non static property, you can not do that. Remove static from them.

Source Link
ghispi
  • 136
  • 1
  • 6

Probably the proper way would be to pass it via constructor as this would allow you to choose which driver phpFastCache() should without interfering with your class. And thats commonly referred as dependency injection. You have to type hint on the phpFastCache() returned instance interface which is phpfastcache_driver. This gives you two things, you can easily change underlying caching mechanism and still lock only to the instances that you know that implement methods you use in your class.

Then the constructor would look like this:

public function __construct(phpfastcache_driver $cache)
{
  $this->cache = $cache;
}

And the initialisation of the class as follows:

$myCache = new Cache(phpFastCache('files'));

or

$myCache = new Cache(phpFastCache('memcached'));

or whatever storage engine phpFastCache supports.