php yac使用,PHP共享内存yac操作类

/**

* 进程间共享内存操作类

*/

class Pshmop

{

protected static $_models = array();

private $_yac = null;

private static $_keyPrefix = 'shm_';

private static $_ttlMaxTime = 7776000;  //86400*90 为防止永久贮存及保存时间过久造成内存消耗严重导致数据被踢出

/**

* Returns the static model of the specified AR class.

* @param string $className active record class name.

* @return Order the static model class

*/

public static function model($className = __CLASS__)

{

$model = null;

if (isset(self::$_models[$className]))

$model = self::$_models[$className];

else {

$model = self::$_models[$className] = new $className(null);

}

return $model;

}

public function __construct() {

if(extension_loaded("yac")){

$this->_yac = new Yac(self::$_keyPrefix);

}

}

/**

* add value

* @param mixed $keys

* @param mixed $value

* @param int $ttl

* @return mixed

*/

public function add($key, $value, $ttl=-1){

if(empty($key)){

return null;

}

if(empty($this->_yac)){

return null;

}

if($ttl<0 || $ttl>self::$_ttlMaxTime){

$ttl = self::$_ttlMaxTime;

}

return $this->_yac->add($key, $value, $ttl);

}

/**

* set value

* @param mixed $keys

* @param mixed $value

* @param int $ttl

* @return mixed

*/

public function set($key, $value, $ttl=-1){

if(empty($key)){

return null;

}

if(empty($this->_yac)){

return null;

}

if($ttl<0 || $ttl>self::$_ttlMaxTime){

$ttl = self::$_ttlMaxTime;

}

return $this->_yac->set($key, $value, $ttl);

}

/**

* get value

* @param mixed $keys

* @return mixed

*/

public function get($key){

if(empty($key)){

return null;

}

if(empty($this->_yac)){

return null;

}

return $this->_yac->get($key);

}

/**

* delete key

* @param mixed $keys

* @param int $delay

* @return mixed

*/

public function delete($key, $delay=0){

if(empty($key)){

return null;

}

if(empty($this->_yac)){

return null;

}

return $this->_yac->delete($key, $delay);

}

/**

* flush shm

* @param void

* @return mixed

*/

public function flush(){

if(empty($this->_yac)){

return null;

}

return $this->_yac->flush();

}

/**

* get shm info

* @param void

* @return mixed

*/

public function info(){

if(empty($this->_yac)){

return null;

}

return $this->_yac->info();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值