Ejemplo n.º 1
0
 /**
  * Prepare a cache library for use, either by loading it from file, filling it with
  * pre existing data in array form, or leaving it empty and waiting for new entries.
  * 
  * @param string $CacheName name of cache library
  * @param array $ExistingCacheArray optional array containing an initial seed cache
  * @param string $CacheMode optional mode of the cache... defaults to flat
  * @return void
  */
 public static function PrepareCache($CacheName, $ExistingCacheArray = NULL, $CacheMode = 'flat')
 {
     // Onetime initialization of in-memory file cache
     if (!is_array(self::$_Caches)) {
         self::$_Caches = array();
     }
     if ($CacheName != 'locale') {
         return;
     }
     if (!array_key_exists($CacheName, self::$_Caches)) {
         $OnDiskCacheName = sprintf(self::DISK_CACHE_NAME_FORMAT, strtolower($CacheName));
         self::$_Caches[$CacheName] = array('ondisk' => $OnDiskCacheName, 'cache' => array(), 'mode' => $CacheMode);
         // Loading cache for the first time by name+path only... import data now.
         if (file_exists(PATH_LOCAL_CACHE . DS . $OnDiskCacheName)) {
             $CacheContents = parse_ini_file(PATH_LOCAL_CACHE . DS . $OnDiskCacheName, TRUE);
             if ($CacheContents != FALSE && is_array($CacheContents)) {
                 self::Import($CacheName, $CacheContents);
             } else {
                 @unlink(PATH_LOCAL_CACHE . DS . $OnDiskCacheName);
             }
         }
     }
     // If cache data array is passed in, merge it with our existing cache
     if (is_array($ExistingCacheArray)) {
         self::Import($CacheName, $ExistingCacheArray, TRUE);
     }
 }
Ejemplo n.º 2
0
 /**
  * Prepare a cache library for use, either by loading it from file, filling it with
  * pre existing data in array form, or leaving it empty an waiting for new entries.
  * 
  * @param string $CacheName name of cache library
  * @param array $ExistingCacheArray optional array containing an initial seed cache
  * @return void
  */
 public static function PrepareCache($CacheName, $ExistingCacheArray = NULL)
 {
     // Onetime initialization of in-memory file cache
     if (!is_array(Gdn_LibraryMap::$_Caches)) {
         Gdn_LibraryMap::$_Caches = array();
     }
     if (!array_key_exists($CacheName, Gdn_LibraryMap::$_Caches)) {
         $OnDiskCacheName = sprintf(Gdn_LibraryMap::DISK_CACHE_NAME_FORMAT, strtolower($CacheName));
         Gdn_LibraryMap::$_Caches[$CacheName] = array('ondisk' => $OnDiskCacheName, 'cache' => array());
         // Loading cache for the first time by name+path only... import data now.
         if (file_exists(PATH_CACHE . DS . $OnDiskCacheName)) {
             require_once PATH_CACHE . DS . $OnDiskCacheName;
         }
     }
     // If cache data array is passed in, merge it with our existing cache
     if (is_array($ExistingCacheArray)) {
         Gdn_LibraryMap::Import($CacheName, $ExistingCacheArray);
     }
 }