You are here

class ShareaholicCache in Share Buttons, Related Posts, Content Analytics - Shareaholic 7.3

Same name and namespace in other branches
  1. 8 cache.php \ShareaholicCache

A simple wrapper around the Drupal caching library because it is incapable of respecting the expire time

@package shareaholic

Hierarchy

Expanded class hierarchy of ShareaholicCache

File

./cache.php, line 14

View source
class ShareaholicCache {

  /**
   * Get the cached item based on the key
   *
   * @param string $key the key to get the cache value for
   * @return mixed the data cached or false if not found
   */
  public static function get($key) {
    $cache = cache_get($key);

    // check if the cache is stale
    if (!$cache) {
      return FALSE;
    }
    if (REQUEST_TIME > $cache->expire) {
      return FALSE;
    }
    return $cache->data;
  }

  /**
   * Updates the cache value given a key and expire time
   *
   * @param string $key the key for the cached data
   * @param mixed $data the data to cache
   * @param integer $expire the number of seconds to cache the data for
   */
  public static function set($key, $data, $expire) {
    $expire_time = REQUEST_TIME + $expire;
    cache_set($key, $data, 'cache', $expire_time);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ShareaholicCache::get public static function Get the cached item based on the key
ShareaholicCache::set public static function Updates the cache value given a key and expire time