diff --git mongodb_cache/mongodb_cache.inc mongodb_cache/mongodb_cache.inc index a2b9d46..092395b 100644 --- mongodb_cache/mongodb_cache.inc +++ mongodb_cache/mongodb_cache.inc @@ -2,13 +2,45 @@ include_once dirname(__FILE__) . '/../mongodb.module'; +function _cache_get_object($bin) { + // We do not use drupal_static() here because we do not want to change the + // storage of a cache bin mid-request. + static $cache_objects; + if (!isset($cache_objects[$bin])) { + $class = 'DrupalMongoDBCache'; + $cache_objects[$bin] = new $class($bin); + } + return $cache_objects[$bin]; +} + +function cache_get($cid, $bin = 'cache') { + return _cache_get_object($bin)->get($cid); +} + +function cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT) { + return _cache_get_object($bin)->set($cid, $data, $expire); +} + +function cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE) { + if (!isset($cid) && !isset($bin)) { + // Clear the block cache first, so stale data will + // not end up in the page cache. + if (module_exists('block')) { + cache_clear_all(NULL, 'cache_block'); + } + cache_clear_all(NULL, 'cache_page'); + return; + } + return _cache_get_object($bin)->clear($cid, $wildcard); +} + /** * MonogoDB cache implementation. * * This is Drupal's default cache implementation. It uses the MongoDB to store * cached data. Each cache bin corresponds to a collection by the same name. */ -class DrupalMongoDBCache implements DrupalCacheInterface { +class DrupalMongoDBCache { protected $bin; function __construct($bin) { diff --git mongodb_cache/mongodb_cache.info mongodb_cache/mongodb_cache.info index 7c0d230..75a746c 100644 --- mongodb_cache/mongodb_cache.info +++ mongodb_cache/mongodb_cache.info @@ -2,7 +2,7 @@ name = MongoDB Cache description = Integration between MongoDB as Cache. package = MongoDB version = VERSION -core = 7.x +core = 6.x files[] = mongodb_cache.module ; Information added by drupal.org packaging script on 2011-04-26