Beispiel #1
0
 function get($key)
 {
     global $user;
     // Load local cache for multiple hits per page.
     if (isset($this->content[$key])) {
         return $this->content[$key];
     }
     // Handle garbage collection
     $this->gc();
     $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {" . $this->name . "} WHERE cid = '%s'", $key));
     if (isset($cache->data)) {
         // If the data is permanent or we're not enforcing a minimum cache lifetime
         // always return the cached data.
         if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) {
             $cache->data = db_decode_blob($cache->data);
             if ($cache->serialized) {
                 $cache->data = unserialize($cache->data);
             }
         } else {
             if ($user->cache > $cache->created) {
                 // This cache data is too old and thus not valid for us, ignore it.
                 return 0;
             } else {
                 $cache->data = db_decode_blob($cache->data);
                 if ($cache->serialized) {
                     $cache->data = unserialize($cache->data);
                 }
             }
         }
         $this->content[$key] = $cache;
         return $cache;
     }
     return 0;
 }
Beispiel #2
0
 function get($key)
 {
     global $user;
     $cache = parent::get($key);
     if ($cache) {
         return $cache;
     }
     $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {" . $this->name . "} WHERE cid = '%s'", $key));
     if (isset($cache->data)) {
         $cache->data = db_decode_blob($cache->data);
         if ($cache->serialized) {
             $cache->data = unserialize($cache->data);
         }
     }
     parent::set($key, $cache);
     return $cache;
 }