PHP 클래스 yii\caching\MemCache

MemCache supports both memcache and memcached. By setting [[useMemcached]] to be true or false, one can let MemCache to use either memcached or memcache, respectively. MemCache can be configured with a list of memcache servers by settings its [[servers]] property. By default, MemCache assumes there is a memcache server running on localhost at port 11211. See Cache for common cache operations that MemCache supports. Note, there is no security measure to protected data in memcache. All data in memcache can be accessed by any process running in the system. To use MemCache as the cache application component, configure the application as follows, php [ 'components' => [ 'cache' => [ 'class' => 'yii\caching\MemCache', 'servers' => [ [ 'host' => 'server1', 'port' => 11211, 'weight' => 60, ], [ 'host' => 'server2', 'port' => 11211, 'weight' => 40, ], ], ], ], ] In the above, two memcache servers are used: server1 and server2. You can configure more properties of each server, such as persistent, weight, timeout. Please see MemCacheServer for available options. For more details and usage information on Cache, see the guide article on caching.
부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends Cache
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$options options for Memcached. This property is used only when [[useMemcached]] is true.
$password memcached sasl password. This property is used only when [[useMemcached]] is true.
$persistentId an ID that identifies a Memcached instance. This property is used only when [[useMemcached]] is true. By default the Memcached instances are destroyed at the end of the request. To create an instance that persists between requests, you may specify a unique ID for the instance. All instances created with the same ID will share the same connection.
$useMemcached whether to use memcached or memcache as the underlying caching extension. If true, memcached will be used. If false, memcache will be used. Defaults to false.
$username memcached sasl username. This property is used only when [[useMemcached]] is true.

공개 메소드들

메소드 설명
getMemcache ( ) : Memcache | Memcached Returns the underlying memcache (or memcached) object.
getServers ( ) : MemCacheServer[] Returns the memcache or memcached server configurations.
init ( ) Initializes this application component.
setServers ( array $config )

보호된 메소드들

메소드 설명
addMemcacheServers ( Memcache $cache, MemCacheServer[] $servers ) Add servers to the server pool of the cache specified Used for memcache PECL extension.
addMemcachedServers ( Memcached $cache, MemCacheServer[] $servers ) Add servers to the server pool of the cache specified Used for memcached PECL extension.
addServers ( Memcache | Memcached $cache, MemCacheServer[] $servers ) Add servers to the server pool of the cache specified
addValue ( string $key, mixed $value, integer $duration ) : boolean Stores a value identified by a key into cache if the cache does not contain this key.
deleteValue ( string $key ) : boolean Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.
flushValues ( ) : boolean Deletes all values from cache.
getValue ( string $key ) : mixed | false Retrieves a value from cache with a specified key.
getValues ( array $keys ) : array Retrieves multiple values from cache with the specified keys.
setValue ( string $key, mixed $value, integer $duration ) : boolean Stores a value identified by a key in cache.
setValues ( array $data, integer $duration ) : array Stores multiple key-value pairs in cache.

메소드 상세

addMemcacheServers() 보호된 메소드

Add servers to the server pool of the cache specified Used for memcache PECL extension.
protected addMemcacheServers ( Memcache $cache, MemCacheServer[] $servers )
$cache Memcache
$servers MemCacheServer[]

addMemcachedServers() 보호된 메소드

Add servers to the server pool of the cache specified Used for memcached PECL extension.
protected addMemcachedServers ( Memcached $cache, MemCacheServer[] $servers )
$cache Memcached
$servers MemCacheServer[]

addServers() 보호된 메소드

Add servers to the server pool of the cache specified
protected addServers ( Memcache | Memcached $cache, MemCacheServer[] $servers )
$cache Memcache | Memcached
$servers MemCacheServer[]

addValue() 보호된 메소드

This is the implementation of the method declared in the parent class.
또한 보기: [Memcache::set()](http://php.net/manual/en/memcache.set.php)
protected addValue ( string $key, mixed $value, integer $duration ) : boolean
$key string the key identifying the value to be cached
$value mixed the value to be cached
$duration integer the number of seconds in which the cached value will expire. 0 means never expire.
리턴 boolean true if the value is successfully stored into cache, false otherwise

deleteValue() 보호된 메소드

Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.
protected deleteValue ( string $key ) : boolean
$key string the key of the value to be deleted
리턴 boolean if no error happens during deletion

flushValues() 보호된 메소드

This is the implementation of the method declared in the parent class.
protected flushValues ( ) : boolean
리턴 boolean whether the flush operation was successful.

getMemcache() 공개 메소드

Returns the underlying memcache (or memcached) object.
public getMemcache ( ) : Memcache | Memcached
리턴 Memcache | Memcached the memcache (or memcached) object used by this cache component.

getServers() 공개 메소드

Returns the memcache or memcached server configurations.
public getServers ( ) : MemCacheServer[]
리턴 MemCacheServer[] list of memcache server configurations.

getValue() 보호된 메소드

This is the implementation of the method declared in the parent class.
protected getValue ( string $key ) : mixed | false
$key string a unique key identifying the cached value
리턴 mixed | false the value stored in cache, false if the value is not in the cache or expired.

getValues() 보호된 메소드

Retrieves multiple values from cache with the specified keys.
protected getValues ( array $keys ) : array
$keys array a list of keys identifying the cached values
리턴 array a list of cached values indexed by the keys

init() 공개 메소드

It creates the memcache instance and adds memcache servers.
public init ( )

setServers() 공개 메소드

또한 보기: http://php.net/manual/en/memcache.addserver.php
또한 보기: http://php.net/manual/en/memcached.addserver.php
public setServers ( array $config )
$config array list of memcache or memcached server configurations. Each element must be an array with the following keys: host, port, persistent, weight, timeout, retryInterval, status.

setValue() 보호된 메소드

This is the implementation of the method declared in the parent class.
또한 보기: [Memcache::set()](http://php.net/manual/en/memcache.set.php)
protected setValue ( string $key, mixed $value, integer $duration ) : boolean
$key string the key identifying the value to be cached
$value mixed the value to be cached.
$duration integer the number of seconds in which the cached value will expire. 0 means never expire.
리턴 boolean true if the value is successfully stored into cache, false otherwise

setValues() 보호된 메소드

Stores multiple key-value pairs in cache.
protected setValues ( array $data, integer $duration ) : array
$data array array where key corresponds to cache key while value is the value stored
$duration integer the number of seconds in which the cached values will expire. 0 means never expire.
리턴 array array of failed keys. Always empty in case of using memcached.

프로퍼티 상세

$options 공개적으로 프로퍼티

options for Memcached. This property is used only when [[useMemcached]] is true.
또한 보기: http://ca2.php.net/manual/en/memcached.setoptions.php
public $options

$password 공개적으로 프로퍼티

memcached sasl password. This property is used only when [[useMemcached]] is true.
또한 보기: http://php.net/manual/en/memcached.setsaslauthdata.php
public $password

$persistentId 공개적으로 프로퍼티

an ID that identifies a Memcached instance. This property is used only when [[useMemcached]] is true. By default the Memcached instances are destroyed at the end of the request. To create an instance that persists between requests, you may specify a unique ID for the instance. All instances created with the same ID will share the same connection.
또한 보기: http://ca2.php.net/manual/en/memcached.construct.php
public $persistentId

$useMemcached 공개적으로 프로퍼티

whether to use memcached or memcache as the underlying caching extension. If true, memcached will be used. If false, memcache will be used. Defaults to false.
public $useMemcached

$username 공개적으로 프로퍼티

memcached sasl username. This property is used only when [[useMemcached]] is true.
또한 보기: http://php.net/manual/en/memcached.setsaslauthdata.php
public $username