Class: AbstractWindCache
Source Location: /cache/AbstractWindCache.php
Class AbstractWindCache
Class Overview
缓存策略实现的基类
该基类继承了框架的基类WindModule,用以提供实现组件的一些特性.同时该类作为缓存策略的基类定义了通用的对方访问接口,及子类需要实现的抽象接口. 定义了缓存可以访问的接口如下: 该基类支持三个配置项setConfig(),所有继承该类的子类都拥有对该三个配置项的配置。the last known user to change this file in the repository <$LastChangedBy: yishuo $>
Located in /cache/AbstractWindCache.php [line 24]
WindModule
|
--AbstractWindCache
Author(s):
API Tags:
Information Tags:
Version: | $Id: AbstractWindCache.php 2973 2011-10-15 19:22:48Z yishuo $ |
Copyright: | ©2003-2103 phpwind.com |
License: | http://www.windframework.com |
|
Methods
|
Inherited Properties, Constants, and Methods
Constant Summary
EXPIRE |
配置文件中标志过期时间名称定义(也包含缓存元数据中过期时间的定义) |
Method Summary
boolean |
add() |
增加一个条目到缓存服务器 |
boolean |
clear() |
清楚缓存,过期及所有缓存 |
mixed |
get() |
根据缓存key获取指定缓存 |
boolean |
set() |
设置缓存 如果key不存在,添加缓存;否则,将会替换已有key的缓存。 |
Methods
增加一个条目到缓存服务器
方法在缓存服务器之前不存在key时, 以key作为key存储一个变量var到缓存服务器。 <note>注意:新的元素的值不会小于0。 并且在元素不存在时不能创建它</note>
Parameters:
API Tags:
Return: | 成功时返回 TRUE, 或者在失败时返回 FALSE. 如果这个key已经存在返回FALSE。 |
Access: | public |
boolean addValue(
string
$key, string
$value, [int
$expires = 0]
)
|
|
执行添加操作
当数据key不存在的时候添加,如果key已经存在则添加失败
Parameters:
string |
$key: |
缓存数据的唯一key |
string |
$value: |
缓存数据值,该值是一个含有有效数据的序列化的字符串 |
int |
$expires: |
缓存数据保存的有效时间,单位为秒,默认时间为0即永不过期 |
API Tags:
Abstract: | |
Access: | protected |
Information Tags:
Throws: | WindException 缓存失败的时候抛出异常 |
Redefined in descendants as:
boolean batchDelete(
array
$keys
)
|
|
通过key批量删除缓存数据
Parameters:
array |
$keys: |
需要批量删除的缓存key组成的组数 |
API Tags:
Redefined in descendants as:
array batchGet(
array
$keys
)
|
|
通过key批量获取缓存数据
Parameters:
API Tags:
Return: | 返回批量key对应的缓存数据组成的缓存数据数组 |
Access: | public |
Redefined in descendants as:
构造保存的数据
Parameters:
API Tags:
string buildSecurityKey(
string
$key
)
|
|
将数据key计算生成安全的key
Parameters:
API Tags:
Return: | 加入安全码计算之后返回的保存key |
Access: | protected |
Redefined in descendants as:
清楚缓存,过期及所有缓存
API Tags:
Redefined in descendants as:
int decrement(
string
$key, [int
$step = 1]
)
|
|
将元素的值减小value
如果指定的key 对应的元素不是数值类型并且不能被转换为数值, 会将此值修改为value. <note>注意:新的元素的值不会小于0。 并且在元素不存在时不能创建它</note>
Parameters:
string |
$key: |
将要增加值的元素的key。 |
int |
$step: |
value参数指要将指定元素的值减小多少。 |
API Tags:
Return: | 成功的时候返回元素的新值,失败的时候返回false。 |
Access: | public |
Redefined in descendants as:
boolean delete(
string
$key
)
|
|
删除缓存数据
Parameters:
string |
$key: |
获取缓存数据的标识,即键 |
API Tags:
Information Tags:
Throws: | WindCacheException 删除失败时抛出异常 |
boolean deleteValue(
string
$key
)
|
|
需要实现的删除操作
Parameters:
string |
$key: |
需要删除的缓存数据的key |
API Tags:
Abstract: | |
Access: | protected |
Redefined in descendants as:
mixed formatData(
string
$key, string
$value
)
|
|
格式化输出
将从缓存对象中获得的缓存源数据进行格式化输出.该源数据是一个格式良好的数组的序列化字符串,需要反序列化获得源数组. 如果没有数据,则返回false 如果含有数据,则返回该数据
Parameters:
string |
$key: |
缓存的key值 |
string |
$value: |
缓存的数据的序列化值 |
API Tags:
Return: | 返回保存的真实数据,如果没有数值则返回false |
Access: | protected |
根据缓存key获取指定缓存
Parameters:
string |
$key: |
获取缓存数据的标识,即键 |
API Tags:
Return: | 返回被缓存的数据 |
Access: | public |
Information Tags:
Throws: | WindCacheException 获取失败时抛出异常 |
返回过期时间设置
单位为秒,默认值为0永不过期
API Tags:
Return: | 缓存过期时间,默认为0永不过期,单位为秒 |
Access: | public |
返回缓存Key值前缀
默认值为null无任何前缀添加
API Tags:
Return: | 返回key前缀 |
Access: | protected |
string getSecurityCode(
)
|
|
获得缓存key计算中加入的安全码
API Tags:
string getValue(
string
$key
)
|
|
执行获取操作
Parameters:
API Tags:
Return: | 缓存的数据 |
Abstract: | |
Access: | protected |
Information Tags:
Throws: | WindException 缓存数据获取失败抛出异常 |
Redefined in descendants as:
boolean hasChanged(
string
$key, array
$data
)
|
|
判断数据是否已经被更新
如果缓存中有数据,则检查缓存依赖是否已经变更,如果变更则删除缓存,并且返回true. 如果没有更新则返回false.
Parameters:
string |
$key: |
缓存的key |
array |
$data: |
缓存中的数据 |
API Tags:
Return: | true表示缓存已变更,false表示缓存未变改 |
Access: | protected |
int increment(
string
$key, [int
$step = 1]
)
|
|
将指定元素的值增加value
如果指定的key 对应的元素不是数值类型并且不能被转换为数值, 会将此值修改为value. <note>注意:不会在key对应元素不存在时创建元素。</note>
Parameters:
string |
$key: |
将要增加值的元素的key。 |
int |
$step: |
参数value表明要将指定元素值增加多少。 |
API Tags:
Return: | 成功时返回新的元素值失败时返回false。 |
Access: | public |
Redefined in descendants as:
设置缓存 如果key不存在,添加缓存;否则,将会替换已有key的缓存。
Parameters:
API Tags:
Information Tags:
Throws: | WindCacheException 缓存失败时抛出异常 |
void setConfig(
array
$config
)
|
|
设置配置信息
支持三个配置项: - security-code: 安全码配置
- key-prefix: key前缀设置
- expires: 缓存过期时间配置,单位为秒,默认为0
Parameters:
API Tags:
Redefinition of:
- WindModule::setConfig()
- 设置类配置
Redefined in descendants as:
void setExpire(
int
$expire
)
|
|
设置缓存过期时间
单位为秒,默认为0永不过期
Parameters:
int |
$expire: |
缓存过期时间,单位为秒,默认为0永不过期 |
API Tags:
void setKeyPrefix(
sting
$keyPrefix
)
|
|
设置key前缀
Parameters:
API Tags:
void setSecurityCode(
string
$securityCode
)
|
|
设置缓存key计算中加入的安全码
Parameters:
string |
$securityCode: |
安全码 |
API Tags:
boolean setValue(
string
$key, string
$value, [int
$expires = 0]
)
|
|
执行设置操作
Parameters:
string |
$key: |
缓存数据的唯一key |
string |
$value: |
缓存数据值,该值是一个含有有效数据的序列化的字符串 |
int |
$expires: |
缓存数据保存的有效时间,单位为秒,默认时间为0即永不过期 |
API Tags:
Abstract: | |
Access: | protected |
Information Tags:
Throws: | WindException 缓存失败的时候抛出异常 |
Redefined in descendants as:
Constants
配置文件中标志过期时间名称定义(也包含缓存元数据中过期时间的定义)
|
|