Esempio n. 1
0
 public function init()
 {
     $this->module_name = "cache";
     $this->module_position = 1;
     $this->version = 2.229;
     // 2.229 - 2014-07-28 - menu generation speed improvement
     // 2.228 - 2014-05-12 - cache bug fixing
     // 2.227 - 2013-10-02 - cache bug fixing
     // 2.226 - 2013-09-12 - hopefully a BIG new speed improvement - change advanced cache_enabled to 1
     // 2.225 - 2013-09-12 - debug_cache advanced option added
     // 2.224 - 2013-09-10 - dashboard speed fix
     // 2.223 - 2013-09-08 - cache size fix
     // 2.222 - 2013-09-06 - cache_objects configuration variable (not cache_object)
     // 2.221 - 2013-09-03 - cache improvements and bug fixing
     // 2.22 - 2013-08-31 - cache and speed improvements
     // 2.21 - 2013-08-30 - better memcache support
     // 2.2 - 2013-08-30 - starting work on memcache support
     // version bug fix? maybe?
     // use memcache if it exists
     if (class_exists('Memcache', false) && module_config::c('cache_enabled', 1) && module_config::c('memcache_active', 0)) {
         self::$_memcache_instance = new Memcache();
         if (self::$_memcache_instance->connect(module_config::c('memcache_address', '127.0.0.1'), module_config::c('memcache_port', '11211'))) {
             //module_config::c('memcache_address','localhost'), )){
             self::$_memcache_prefix = md5(session_id() . _UCM_SECRET . _DB_PREFIX . _DB_NAME . _DB_USER . _DB_PASS);
             // what version of information are we requesting (inremented each time something is deleted, inserted or updated)
             // bad, but cannot think of any other easy quick way to invalidate caches upon updates
             self::$_memcache_version = self::$_memcache_instance->get(self::$_memcache_prefix . 'version');
             if (!self::$_memcache_version) {
                 self::$_memcache_version = 1;
             }
             self::$_use_memcache = true;
         }
     } else {
         if (module_config::c('cache_enabled', 1) && $this->db_table_exists('cache_store')) {
             $sql = "SELECT * FROM `" . _DB_PREFIX . "cache_store` WHERE expire_time > " . time();
             foreach (qa($sql) as $res) {
                 if (!isset(self::$_db_cache[$res['cache_group']])) {
                     self::$_db_cache[$res['cache_group']] = array();
                 }
                 self::$_db_cache[$res['cache_group']][$res['cache_key']] = $res['cache_data'];
             }
             register_shutdown_function('module_cache::shutdown_write_cached_data');
         }
     }
     // change to low number by default
     if (module_config::c('cache_objects', 120) == 3600) {
         module_config::save_config('cache_objects', 120);
     }
     if (module_config::c('cache_enabled', 1) && $this->db_table_exists('cache')) {
         $sql = "SELECT * FROM `" . _DB_PREFIX . "cache`";
         foreach (qa($sql) as $r) {
             self::$_cache_expiry[$r['cache_group']] = $r['expire_time'];
         }
     }
 }