mirror of
https://github.com/Mibew/mibew.git
synced 2025-05-09 21:53:07 +03:00
Add support of memcached storage for caching
This commit is contained in:
parent
758203b6d3
commit
22aaedd3be
@ -42,7 +42,7 @@ mailer:
|
|||||||
# Cache subsystem
|
# Cache subsystem
|
||||||
cache:
|
cache:
|
||||||
# This value determines where the cached data will be stored. Possible
|
# This value determines where the cached data will be stored. Possible
|
||||||
# values are "none" and "file_system".
|
# values are "none", "file_system" and "memcached".
|
||||||
#
|
#
|
||||||
# If "none" is used the caching will be disabled. This option should be used
|
# If "none" is used the caching will be disabled. This option should be used
|
||||||
# only if none of the other options works.
|
# only if none of the other options works.
|
||||||
@ -50,8 +50,17 @@ cache:
|
|||||||
# If "file_system" is used the cached data will be stored in files within
|
# If "file_system" is used the cached data will be stored in files within
|
||||||
# the "cache/" directory. Notice, that the file system storage does not work
|
# the "cache/" directory. Notice, that the file system storage does not work
|
||||||
# on NFS systems bucause exclusive file locks are not supported where.
|
# on NFS systems bucause exclusive file locks are not supported where.
|
||||||
|
#
|
||||||
|
# If "memcached" is used the cached data will be stored in Memcached
|
||||||
|
# storage. Before using this kind of storage make sure PHP's memcached
|
||||||
|
# extension is installed and enabled.
|
||||||
storage: file_system
|
storage: file_system
|
||||||
|
|
||||||
|
# The lines below represents default Memcached server configurations. They
|
||||||
|
# will be used only if the "storage" option is set to "memcached".
|
||||||
|
memcached_host: localhost
|
||||||
|
memcached_port: 11211
|
||||||
|
|
||||||
# Locales
|
# Locales
|
||||||
## Native name will be used in this locale
|
## Native name will be used in this locale
|
||||||
home_locale: en
|
home_locale: en
|
||||||
|
@ -22,6 +22,7 @@ namespace Mibew\Cache;
|
|||||||
use Stash\Interfaces\PoolInterface;
|
use Stash\Interfaces\PoolInterface;
|
||||||
use Stash\Driver\Ephemeral as EphemeralDriver;
|
use Stash\Driver\Ephemeral as EphemeralDriver;
|
||||||
use Stash\Driver\FileSystem as FileSystemDriver;
|
use Stash\Driver\FileSystem as FileSystemDriver;
|
||||||
|
use Stash\Driver\Memcache as MemcacheDriver;
|
||||||
use Stash\Pool as CachePool;
|
use Stash\Pool as CachePool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,6 +98,8 @@ class CacheFactory
|
|||||||
$defaults = array(
|
$defaults = array(
|
||||||
'storage' => 'file_system',
|
'storage' => 'file_system',
|
||||||
'path' => '/tmp',
|
'path' => '/tmp',
|
||||||
|
'memcached_host' => 'localhost',
|
||||||
|
'memcached_port' => 11211,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Make sure all passed options are known
|
// Make sure all passed options are known
|
||||||
@ -124,6 +127,9 @@ class CacheFactory
|
|||||||
/**
|
/**
|
||||||
* Builds cache pool instance.
|
* Builds cache pool instance.
|
||||||
*
|
*
|
||||||
|
* @todo Most likely the factory should return Ephemeral cache if a real
|
||||||
|
* storage cannot be used by some resons.
|
||||||
|
*
|
||||||
* @return PoolInterface An instance of cache pool.
|
* @return PoolInterface An instance of cache pool.
|
||||||
* @throws \RuntimeException If at least one of factory's options is
|
* @throws \RuntimeException If at least one of factory's options is
|
||||||
* invalid.
|
* invalid.
|
||||||
@ -137,6 +143,16 @@ class CacheFactory
|
|||||||
} elseif ($storage === 'file_system') {
|
} elseif ($storage === 'file_system') {
|
||||||
$driver = new FileSystemDriver();
|
$driver = new FileSystemDriver();
|
||||||
$driver->setOptions(array('path' => $this->getOption('path')));
|
$driver->setOptions(array('path' => $this->getOption('path')));
|
||||||
|
} elseif ($storage === 'memcached') {
|
||||||
|
$driver = new MemcacheDriver();
|
||||||
|
$driver->setOptions(array(
|
||||||
|
'servers' => array(
|
||||||
|
$this->getOption('memcached_host'),
|
||||||
|
$this->getOption('memcached_port'),
|
||||||
|
),
|
||||||
|
// Use only PHP's "memcached" extension.
|
||||||
|
'extension' => 'memcached'
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException(sprintf(
|
throw new \RuntimeException(sprintf(
|
||||||
'Wrong value of "storage" option: "%s"',
|
'Wrong value of "storage" option: "%s"',
|
||||||
|
Loading…
Reference in New Issue
Block a user