【opencart3源码分析】memcache缓存类mem.php

<?php
namespace Cache;
/**
 * memcache 缓存类
 * @package Cache
 */
class Mem {
    // 过期时间
	private $expire;
	private $memcache;
	// 缓存输出大小限制
	const CACHEDUMP_LIMIT = 9999;

	public function __construct($expire) {
		$this->expire = $expire;
        // 实例化memcache类
		$this->memcache = new \Memcache();
		$this->memcache->pconnect(CACHE_HOSTNAME, CACHE_PORT);
	}

	// 读取缓存
	public function get($key) {
		return $this->memcache->get(CACHE_PREFIX . $key);
	}

	// 设置缓存
	public function set($key, $value) {
		return $this->memcache->set(CACHE_PREFIX . $key, $value, MEMCACHE_COMPRESSED, $this->expire);
	}

	// 删除缓存
	public function delete($key) {
		$this->memcache->delete(CACHE_PREFIX . $key);
	}
}

猜你喜欢

转载自blog.csdn.net/qq2942713658/article/details/81430927