dev-master
9999999-devCache service provider for Silex application
MIT
The Requires
- php >=5.3.3
- pimple/pimple >1.0
The Development Requires
by Quentin Aupetit
service cache library silex provider
Wallogit.com
2017 © Pedro Peláez
Cache service provider for Silex application
The Silex Cache service provider allows you to use several PHP opcode cache in your Silex application., (*2)
To enable it, add this dependency to your composer.json file:, (*3)
{
"require": {
"gadelkareem/silex-cache": "1.0.*@dev"
}
}
apc, array, file, memcache, memcached, xcache, redis, wincache.file cache driver, specifies the path to the cache directorymemcache cache driver, provide the Memcache instance to use. If not defined, a default Memcache object will be instanciated. See the Memcache documentation for additional informations : PHP: Memcache - Manual
memcached cache driver, provide the Memcached instance to use. If not defined, a default Memcached object will be instanciated. See the Memcached documentation for additional informations : PHP: Memcached - Manual
redis cache driver, provide the Redis instance to use. If not defined, a default Redis object will be instanciated. See the PhpRedis documentation for additional informations : PhpRedis
$app->register(new Moust\Silex\Provider\CacheServiceProvider(), array(
'cache.options' => array(
'driver' => 'apc'
)
));
The Cache provider provides a cache service. Here is a usage example:, (*4)
// stores a variable
$app['cache']->store('foo', 'bar');
// stores a variable with a 1 minute lifetime
$app['cache']->store('foo', 'bar', 60);
// fetch variable
echo $app['cache']->fetch('foo');
// delete variable
$app['cache']->delete('foo');
// clear all cached variables
$app['cache']->clear();
The Cache provider can allow access to multiple caches. In order to configure the cache drivers, replace the cache.options with caches.options. caches.options is an array of configurations where keys are cache names and values are options:, (*5)
$app->register(new Moust\Silex\Provider\CacheServiceProvider(), array(
'caches.options' => array(
'apc' => array(
'driver' => 'apc'
),
'filesystem' => array(
'driver' => 'file',
'cache_dir' => './temp'
),
'memory' => array(
'driver' => 'array'
),
'memcache' => array(
'driver' => 'memcache',
'memcache' => function () {
$memcache = new \Memcache;
$memcache->connect('localhost', 11211);
return $memcache;
}
)
)
));
The first registered cache is the default and can simply be accessed as you would if there was only one. Given the above configuration, these two lines are equivalent:, (*6)
$app['cache']->store('foo', 'bar');
$app['caches']['apc']->store('foo', 'bar');
Copyright (c) 2014 Quentin Aupetit, (*7)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*8)
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*9)
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*10)
Cache service provider for Silex application
MIT
service cache library silex provider