From dc481bdaa15fd484f0c995b597bf7d732673f558 Mon Sep 17 00:00:00 2001
From: Mark Sonnabaum <mark@sonnabaum.com>
Date: Sat, 19 Mar 2011 00:31:06 -0500
Subject: [PATCH] Initial backport of mongodb cache to drupal 6.

---
 mongodb_cache/mongodb_cache.inc  |   36 +++++++++++++++++++++++++++++++++++-
 mongodb_cache/mongodb_cache.info |    2 +-
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git mongodb_cache/mongodb_cache.inc mongodb_cache/mongodb_cache.inc
index a2b9d46..b8b0ce4 100644
--- mongodb_cache/mongodb_cache.inc
+++ mongodb_cache/mongodb_cache.inc
@@ -2,13 +2,47 @@
 
 include_once dirname(__FILE__) . '/../mongodb.module';
 
+define('REQUEST_TIME', $_SERVER['REQUEST_TIME']);
+
+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 4e93d54..7c686e7 100644
--- mongodb_cache/mongodb_cache.info
+++ mongodb_cache/mongodb_cache.info
@@ -2,5 +2,5 @@ name = MongoDB Cache
 description = Integration between MongoDB as Cache.
 package = MongoDB
 version = VERSION
-core = 7.x
+core = 6.x
 files[] = mongodb_cache.module
-- 
1.7.4.1

