Esempio n. 1
0
 public static function get($key)
 {
     // Garbage collection
     if (mt_rand(0, 2000) == 1022) {
         Cache_Memory::clearExpired();
     }
     // Get the Cached Value
     if (!($keyData = Database::selectOne("SELECT value, expire FROM cache WHERE `key`=? LIMIT 1", array($key)))) {
         return false;
     }
     // If the Cached Value is expired, delete it and return false
     if ((int) $keyData['expire'] <= time()) {
         self::delete($key);
         return false;
     }
     return isset($keyData['value']) ? $keyData['value'] : false;
 }
 public static function initialize()
 {
     self::$memConn = new Memcached();
     self::$memConn->addServer('localhost', 11211);
     return true;
 }
 public function install()
 {
     return Cache_Memory::sql();
 }
Esempio n. 4
0
function GetBestCategory($search_data)
{
    if (Cache_Memory::IsCached(CACHE_CATEGORIES)) {
        $categories = Cache_Memory::Get(CACHE_CATEGORIES);
    } else {
        $DB = GetDB();
        $categories = $DB->FetchAll('SELECT * FROM `tbx_category`');
        Cache_Memory::Cache(CACHE_CATEGORIES, $categories);
    }
    $best_score = 0;
    $best_category_id = null;
    foreach ($categories as $category) {
        if (!String::IsEmpty($category['auto_category_term']) && preg_match('~(' . str_replace(',', '|', preg_quote($category['auto_category_term'])) . ')~i', $search_data, $matches)) {
            if (count($matches[1]) > $best_score) {
                $best_score = count($matches[1]);
                $best_category_id = $category['category_id'];
            }
        }
    }
    return $best_category_id;
}