选择语言 :

Module_Cache

缓存核心类

常量
Cache::DRIVER_APC string(3) "Apc"
Cache::DRIVER_DATABASE string(8) "Database"
Cache::DRIVER_FILE string(4) "File"
Cache::DRIVER_MEMCACHE string(8) "Memcache"
Cache::DRIVER_REDIS string(5) "Redis"
Cache::DRIVER_SQLITE string(6) "SQLite"
Cache::DRIVER_WINCACHE string(8) "WinCache"
Cache::TYPE_MAX_AGE string(3) "age"
Cache::TYPE_MAX_HIT string(3) "hit"
Cache::TYPE_ADV_AGE string(9) "renew_age"
Cache::TYPE_ADV_HIT string(9) "renew_hit"
Cache::DEFAULT_CONFIG_NAME string(7) "default"

API - Module_Cache

author
呼吸二氧化碳 jonwang@myqee.com
category
Module
package
Cache
copyright
Copyright © 2008-2013 myqee.com
license
http://www.myqee.com/license.html

Cache::instance( $name = null)

返回实例化对象

参数列表

参数 类型 描述 默认值
$name string 默认值为 Cache::DEFAULT_CONFIG_NAME null
返回值
  • Cache

$this->__construct( )


$this->get( $key )

获取指定KEY的缓存数据

$cache->get('a');
$cache->get('a','b','c');
$cache->get(array('a','b','c'));

参数列表

参数 类型 描述 默认值
$key string 指定key
返回值
  • mixed
  • false 返回失败

$this->get_and_delete( $key )

获取数据后立即删除

参数列表

参数 类型 描述 默认值
$key string $key

$this->set( $key , $value = null, $expire = 3600, $expire_type = null)

设置指定key的缓存数据

$expire_type默认有4种类型,分别为:

  • $expire_type = Cache::TYPE_MAX_AGE 最长时间,当指定的$expire达到时间后,缓存失效,默认方式
  • $expire_type = Cache::TYPE_MAX_HIT 最大命中数,当get()请求数量达到$expire值后,缓存失效
  • $expire_type = Cache::TYPE_ADV_AGE 高级时效类型,此类型时,传入的$expire可以类似:200~250,1/100,其中200~250表示介于这个时间(单位秒)内时,在1/100请求几率下会失效,其它99/100请求不会失效,并且250为临界时间,超过这个时间将等同TYPE_MAX_AGE方式处理。它的主要用途是在高并发的情况下,避免因缓存失效而集中需要更新导致重复加载。
  • $expire_type = Cache::TYPE_ADV_HIT 高级命中类型,此类型基本同上,只是$expire前的数值表示为请求数

参数列表

参数 类型 描述 默认值
$key string/array 可以同时设置多个
$value fixed $value null
$expire int/string 失效时间或命中数,0表示最大有效时间 integer 3600
$expire_type string 失效类型 null
返回值
  • boolean 是否成功

$this->delete( $key )

删除指定key的缓存数据

参数列表

参数 类型 描述 默认值
$key string $key
返回值
  • boolean

$this->clean( )

删除全部缓存

delete_all()的别名

返回值
  • boolean

$this->delete_all( )

删除全部缓存

返回值
  • boolean

$this->delete_expired( )

删除过期数据

返回值
  • boolean

$this->decrement( $key , $offset = 1, $lifetime = 3600)

递减

与原始decrement方法区别的是若memcache不存指定KEY时返回false,这个会自动递减

参数列表

参数 类型 描述 默认值
$key string $key
$offset int $offset integer 1
$lifetime int 当递减失则时当作set使用 integer 3600

$this->increment( $key , $offset = 1, $lifetime = 3600)

递增

与原始increment方法区别的是若memcache不存指定KEY时返回false,这个会自动递增

参数列表

参数 类型 描述 默认值
$key string $key
$offset int $offset integer 1
$lifetime int 当递减失则时当作set使用 integer 3600

$this->last_error_msg( )

获取错误信息

返回值
  • string

$this->last_error_no( )

获取错误号

返回值
  • int

$this->session_mode( $open )

设置当前为是否为Session获取模式

设置为session模式后,在开启debug情况下访问无缓存状态将不受影响

参数列表

参数 类型 描述 默认值
$open boolean $open
返回值
  • Cache

$this->__get( )


$this->__set( )


$this->__unset( )


$this->__call( )


$this->_check_adv_data( & $key , & $value , & $expire , $type )

格式化set数据

参数列表

参数 类型 描述 默认值
$key string/array $key
$value mixed $value
$expire string $type
$type unknown
返回值
  • boolean/string $exp_key

$this->_get_adv_data( )


$this->load_config( $name )

根据配置名加载配置

参数列表

参数 类型 描述 默认值
$name string $name

$this->check_file_config( $name )

检查文件缓存配置

参数列表

参数 类型 描述 默认值
$name string $name