123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace Elgg\Cache;
- /**
- * WARNING: API IN FLUX. DO NOT USE DIRECTLY.
- *
- * @access private
- *
- * @package Elgg.Core
- * @subpackage Cache
- * @since 1.10.0
- */
- class SystemCache {
- /**
- * Global Elgg configuration
- *
- * @var \stdClass
- */
- private $CONFIG;
- /**
- * Constructor
- */
- public function __construct() {
- global $CONFIG;
- $this->CONFIG = $CONFIG;
- }
- /**
- * Returns an \ElggCache object suitable for caching system information
- *
- * @todo Can this be done in a cleaner way?
- * @todo Swap to memcache etc?
- *
- * @return \ElggFileCache
- */
- function getFileCache() {
-
-
- /**
- * A default filestore cache using the dataroot.
- */
- static $FILE_PATH_CACHE;
-
- if (!$FILE_PATH_CACHE) {
- $FILE_PATH_CACHE = new \ElggFileCache($this->CONFIG->dataroot . 'system_cache/');
- }
-
- return $FILE_PATH_CACHE;
- }
-
- /**
- * Reset the system cache by deleting the caches
- *
- * @return void
- */
- function reset() {
- $this->getFileCache()->clear();
- }
-
- /**
- * Saves a system cache.
- *
- * @param string $type The type or identifier of the cache
- * @param string $data The data to be saved
- * @return bool
- */
- function save($type, $data) {
-
-
- if ($this->CONFIG->system_cache_enabled) {
- return $this->getFileCache()->save($type, $data);
- }
-
- return false;
- }
-
- /**
- * Retrieve the contents of a system cache.
- *
- * @param string $type The type of cache to load
- * @return string
- */
- function load($type) {
-
-
- if ($this->CONFIG->system_cache_enabled) {
- $cached_data = $this->getFileCache()->load($type);
-
- if ($cached_data) {
- return $cached_data;
- }
- }
-
- return null;
- }
-
- /**
- * Enables the system disk cache.
- *
- * Uses the 'system_cache_enabled' datalist with a boolean value.
- * Resets the system cache.
- *
- * @return void
- */
- function enable() {
-
-
- _elgg_services()->datalist->set('system_cache_enabled', 1);
- $this->CONFIG->system_cache_enabled = 1;
- $this->reset();
- }
-
- /**
- * Disables the system disk cache.
- *
- * Uses the 'system_cache_enabled' datalist with a boolean value.
- * Resets the system cache.
- *
- * @return void
- */
- function disable() {
-
-
- _elgg_services()->datalist->set('system_cache_enabled', 0);
- $this->CONFIG->system_cache_enabled = 0;
- $this->reset();
- }
-
- /**
- * Loads the system cache during engine boot
- *
- * @see elgg_reset_system_cache()
- * @access private
- */
- function loadAll() {
-
-
- $this->CONFIG->system_cache_loaded = false;
-
- $this->CONFIG->views = new \stdClass();
- $data = $this->load('view_locations');
- if (!is_string($data)) {
- return;
- }
- $this->CONFIG->views->locations = unserialize($data);
-
- $data = $this->load('view_types');
- if (!is_string($data)) {
- return;
- }
- $this->CONFIG->view_types = unserialize($data);
- // Note: We don't need view_overrides for operation. Inspector can pull this from the cache
-
- $this->CONFIG->system_cache_loaded = true;
- }
-
- /**
- * Initializes the simplecache lastcache variable and creates system cache files
- * when appropriate.
- *
- * @access private
- */
- function init() {
- if (!$this->CONFIG->system_cache_enabled) {
- return;
- }
- // cache system data if enabled and not loaded
- if (!$this->CONFIG->system_cache_loaded) {
- $this->save('view_locations', serialize($this->CONFIG->views->locations));
- $this->save('view_types', serialize($this->CONFIG->view_types));
- // this is saved just for the inspector and is not loaded in loadAll()
- $this->save('view_overrides', serialize(_elgg_services()->views->getOverriddenLocations()));
- }
-
- if (!$this->CONFIG->i18n_loaded_from_cache) {
- _elgg_services()->translator->reloadAllTranslations();
- foreach ($this->CONFIG->translations as $lang => $map) {
- $this->save("$lang.lang", serialize($map));
- }
- }
- }
- }
|