Skip to content

Instantly share code, notes, and snippets.

@daanporon
Created December 20, 2010 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daanporon/748701 to your computer and use it in GitHub Desktop.
Save daanporon/748701 to your computer and use it in GitHub Desktop.
Cache class that can be used in the ca-sdk-loader project. This integrates with the caching system of Drupal
<?php
class CaDrupalCache {
private $cacheTable = 'cache';
private $expire = 3600;
public function __construct($config=array()) {
if(isset($config['cache_table']) && $config['cache_table'] != null) {
$this->cacheTable = $config['cache_table'];
}
if(isset($config['expire']) && $config['expire'] != null) {
$this->expire = $config['expire'];
}
}
public function load($key) {
$cache = cache_get($key, $this->cacheTable);
if(isset($cache->expire) && $cache->expire <= time()) {
return null;
}
if($cache) {
return $cache->data;
}
return null;
}
public function save($value, $key) {
if($this->expire > 0) {
$e = time() + $this->expire;
} else {
$e = $this->expire;
}
cache_set($key, $value, $this->cacheTable, $e);
return $this;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment