예제 #1
0
파일: mem.php 프로젝트: laiello/hecart
 /**
  * hash数组,将数组中的某个字段值索引成数组的KEY
  *
  * @param array  $arr         需要HASH的数组
  * @param string $key         要定的数组字段名
  * @param array  $mem_type    需要HASH的数组
  * @param int    $expire      有效期以分钟为单位,为0时则永不过期只有当MEM服务器关闭才过期
  * @return array|mixed 返回数据
  */
 public function &mem_hash($arr, $key, $mem_type, $expire = 30)
 {
     if (empty($arr) || !is_array($arr)) {
         return $arr;
     }
     $mem_type = "{$mem_type}-{$key}";
     $res = $this->mem->get(__FUNCTION__, $mem_type);
     if (!empty($res)) {
         return $res;
     }
     /**
      * 将数据进行hash
      */
     $res = array();
     foreach ($arr as $v) {
         if (isset($v[$key])) {
             $res[$v[$key]] = $v;
         }
     }
     /**
      * 存储数据并返回数据
      */
     $this->mem->set(__FUNCTION__, $mem_type, $res, $expire);
     return $res;
 }
예제 #2
0
파일: session.php 프로젝트: laiello/hecart
 /**
  * 清空所有SESSION
  *
  * @return boolean
  */
 public function cleanup()
 {
     switch ($this->_type) {
         case 'mem':
             return $this->_mem->flush();
         case 'db':
         case 'mdb':
             return $this->_db->truncate($this->_opt);
         case 'file':
             return self::kill_sfile($this->_path, true);
         case 'dir':
             $dir = 'abcdefghijklmnopqrstuvwxyz';
             $len = strlen($dir);
             for ($i = 0; $i < $len; ++$i) {
                 wcore_fso::rm_dir($dir[$i]);
             }
         default:
             return true;
     }
 }