Created
December 20, 2010 17:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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