Skip to content

Instantly share code, notes, and snippets.

@hkulekci
Last active March 15, 2023 03:58
Show Gist options
  • Save hkulekci/5553902 to your computer and use it in GitHub Desktop.
Save hkulekci/5553902 to your computer and use it in GitHub Desktop.
memcache library for opencart
<?php
class Mcache {
private $memcache;
private $cache_time = 100;
private $cache_zip = false;
private $log_status = false;
private $cache_log = "cache.log";
public function __construct(){
$this->memcache = new Memcache;
@$this->memcache->connect('127.0.0.1', 11211) or define("MEMCACHE_DIED", true); //connect to memcached server
}
public function set($key, $value, $zip = false , $time = 0){
if (!defined('MEMCACHE_DIED')):
$this->log($key . " was set!");
if (!$time):
$time = $this->cache_time;
endif;
$this->memcache->set($key, $value, false, $time);
endif;
}
public function get($key){
if (!defined('MEMCACHE_DIED')):
$this->log($key . " was gotten!");
$value = $this->memcache->get($key);
return $value;
else:
return false;
endif;
}
public function delete($key){
if (!defined('MEMCACHE_DIED')):
$this->log($key . " was deleted!");
$this->memcache->delete($key);
return $value;
else:
return false;
endif;
}
public function log($message) {
$file = DIR_LOGS . $this->cache_log;
if ($this->log_status):
$handle = fopen($file, 'a+');
fwrite($handle, date('Y-m-d G:i:s') . ' - ' . $message . "\n");
fclose($handle);
endif;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment