Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CApcCache
  • CCache
  • CDbCache
  • CDummyCache
  • CEAcceleratorCache
  • CFileCache
  • CMemCache
  • CMemCacheServerConfiguration
  • CRedisCache
  • CWinCache
  • CXCache
  • CZendDataCache
  • X2FileCache

Interfaces

  • ICache
  • ICacheDependency
  • Overview
  • Package
  • Class
  • Tree

Class CMemCache

CMemCache implements a cache application component based on memcached.

CMemCache can be configured with a list of memcache servers by settings its setServers servers property. By default, CMemCache assumes there is a memcache server running on localhost at port 11211.

See CCache manual for common cache operations that are supported by CMemCache.

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 CMemCache as the cache application component, configure the application as follows,

array(
    'components'=>array(
        'cache'=>array(
            'class'=>'CMemCache',
            'servers'=>array(
                array(
                    'host'=>'server1',
                    'port'=>11211,
                    'weight'=>60,
                ),
                array(
                    'host'=>'server2',
                    'port'=>11211,
                    'weight'=>40,
                ),
            ),
        ),
    ),
)

In the above, two memcache servers are used: server1 and server2. You can configure more properties of every server, including: host, port, persistent, weight, timeout, retryInterval, status. See http://www.php.net/manual/en/function.memcache-addserver.php for more details.

CMemCache can also be used with memcached. To do so, set CMemCache::$useMemcached to be true.

CComponent
Extended by CApplicationComponent implements IApplicationComponent
Extended by CCache implements ICache, ArrayAccess
Extended by CMemCache
Package: system\caching
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/caching/CMemCache.php
Methods summary
public
# init( )

Initializes this application component. This method is required by the IApplicationComponent interface. It creates the memcache instance and adds memcache servers.

Initializes this application component. This method is required by the IApplicationComponent interface. It creates the memcache instance and adds memcache servers.

Throws

CException
if memcache extension is not loaded

Overrides

CCache::init()
public Memcache|Memcached
# getMemCache( )

Returns

Memcache|Memcached
the memcache instance (or memcached if CMemCache::$useMemcached is true) used by this component.

Throws

CException
if extension isn't loaded
public array
# getServers( )

Returns

array
list of memcache server configurations. Each element is a CMemCacheServerConfiguration.
public
# setServers( array $config )

Parameters

$config
array
$config list of memcache server configurations. Each element must be an array with the following keys: host, port, persistent, weight, timeout, retryInterval, status.

See

http://www.php.net/manual/en/function.Memcache-addServer.php
protected string|boolean
# getValue( string $key )

Retrieves a value from cache with a specified key. This is the implementation of the method declared in the parent class.

Retrieves a value from cache with a specified key. This is the implementation of the method declared in the parent class.

Parameters

$key
string
$key a unique key identifying the cached value

Returns

string|boolean
the value stored in cache, false if the value is not in the cache or expired.

Throws

CException
if this method is not overridden by child classes

Overrides

CCache::getValue()
protected array
# getValues( array $keys )

Retrieves multiple values from cache with the specified keys.

Retrieves multiple values from cache with the specified keys.

Parameters

$keys
array
$keys a list of keys identifying the cached values

Returns

array
a list of cached values indexed by the keys

Overrides

CCache::getValues()
protected boolean
# setValue( string $key, string $value, integer $expire )

Stores a value identified by a key in cache. This is the implementation of the method declared in the parent class.

Stores a value identified by a key in cache. This is the implementation of the method declared in the parent class.

Parameters

$key
string
$key the key identifying the value to be cached
$value
string
$value the value to be cached
$expire
integer
$expire the number of seconds in which the cached value will expire. 0 means never expire.

Returns

boolean
true if the value is successfully stored into cache, false otherwise

Throws

CException
if this method is not overridden by child classes

Overrides

CCache::setValue()
protected boolean
# addValue( string $key, string $value, integer $expire )

Stores a value identified by a key into cache if the cache does not contain this key. This is the implementation of the method declared in the parent class.

Stores a value identified by a key into cache if the cache does not contain this key. This is the implementation of the method declared in the parent class.

Parameters

$key
string
$key the key identifying the value to be cached
$value
string
$value the value to be cached
$expire
integer
$expire the number of seconds in which the cached value will expire. 0 means never expire.

Returns

boolean
true if the value is successfully stored into cache, false otherwise

Throws

CException
if this method is not overridden by child classes

Overrides

CCache::addValue()
protected boolean
# deleteValue( string $key )

Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.

Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.

Parameters

$key
string
$key the key of the value to be deleted

Returns

boolean
if no error happens during deletion

Throws

CException
if this method is not overridden by child classes

Overrides

CCache::deleteValue()
protected boolean
# flushValues( )

Deletes all values from cache. This is the implementation of the method declared in the parent class.

Deletes all values from cache. This is the implementation of the method declared in the parent class.

Returns

boolean
whether the flush operation was successful.

Throws

CException
if this method is not overridden by child classes

Since

1.1.5

Overrides

CCache::flushValues()
Methods inherited from CCache
add(), delete(), flush(), generateUniqueKey(), get(), mget(), offsetExists(), offsetGet(), offsetSet(), offsetUnset(), set()
Methods inherited from CApplicationComponent
getIsInitialized()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Properties summary
public boolean $useMemcached false
#

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.

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.

Properties inherited from CCache
$hashKey, $keyPrefix, $serializer
Properties inherited from CApplicationComponent
$behaviors
Magic properties summary
public mixed $memCache
#

The memcache instance (or memcached if CMemCache::$useMemcached is true) used by this component.

The memcache instance (or memcached if CMemCache::$useMemcached is true) used by this component.

public array $servers
#

List of memcache server configurations. Each element is a CMemCacheServerConfiguration.

List of memcache server configurations. Each element is a CMemCacheServerConfiguration.

Magic properties inherited from CApplicationComponent
$isInitialized
API documentation generated by ApiGen 2.8.0