Wrapper function for Laravel cache system for easier integration of the cache system in standalone projects. Refer to Laravel documentation for all cache related function. This wrapper support Laravel ArrayStore
, FileStore
, MemcachedStore
and RedisStore
.
For any store driver, you first need to create a new *Store
, passing the config values for each of those stores. Once a new store instantiated, you need to use the instance
function to get the cache instance.
To use one of the following stores, you first need to include add it to the use
list of your class or php file.
The ArrayStore is a dummy store that doesn't really save anything. This can be used if you want to disable cache globally.
The ArrayStore
accepts no parameters: new ArrayStore();
Example :
use UserFrosting\Cache\ArrayStore;
...
$cacheStore = new ArrayStore();
$cache = $cacheStore->instance();
$cache->get(...);
The FileStore save file to the filesystem.
The FileStore
accepts the path
parameter : new FileStore(string $path = "./");
Example :
use UserFrosting\Cache\FileStore;
...
$cacheStore = new FileStore("./cache");
$cache = $cacheStore->instance();
$cache->get(...);
The MemcachedStore uses Memcached to efficiently handle caching.
Memcached should't be mistaken for the Memcache. Those are tow separate things !
The MemcachedStore
accepts the config
parameter : new MemcachedStore(array $config = []);
Memcached config's array contain the settings for your Memcached instance. Default values are:
[
'host' => '127.0.0.1',
'port' => 11211,
'weight' => 100
]
Custom config can be overwritten using this parameter.
Example :
use UserFrosting\Cache\MemcachedStore;
...
$cacheStore = new MemcachedStore(); //Uses default Memcached settings
$cache = $cacheStore->instance();
$cache->get(...);
Example with custom server and port :
use UserFrosting\Cache\MemcachedStore;
...
$cacheStore = new MemcachedStore([
'host' => '123.456.789.0',
'port' => '22122'
]);
$cache = $cacheStore->instance();
$cache->get(...);
The RedisStore uses Redis server to efficiently handle caching.
The RedisStore
accepts the config
parameter : new RedisStore(array $config = []);
Redis config's array contain the settings for your Redis server. Default values are:
[
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'database' => 0
]
Custom config can be overwritten using this parameter.
Example :
use UserFrosting\Cache\RedisStore;
...
$cacheStore = new RedisStore(); //Uses default Redis settings
$cache = $cacheStore->instance();
$cache->get(...);
Example with custom port and password :
use UserFrosting\Cache\RedisStore;
...
$cacheStore = new RedisStore([
'password' => 'MyAwesomePassword',
'port' => '1234'
]);
$cache = $cacheStore->instance();
$cache->get(...);