123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace Elgg\Cache;
- class SystemCache {
-
- private $CONFIG;
-
- public function __construct() {
- global $CONFIG;
- $this->CONFIG = $CONFIG;
- }
-
- function getFileCache() {
-
-
-
- static $FILE_PATH_CACHE;
-
- if (!$FILE_PATH_CACHE) {
- $FILE_PATH_CACHE = new \ElggFileCache($this->CONFIG->dataroot . 'system_cache/');
- }
-
- return $FILE_PATH_CACHE;
- }
-
-
- function reset() {
- $this->getFileCache()->clear();
- }
-
-
- function save($type, $data) {
-
-
- if ($this->CONFIG->system_cache_enabled) {
- return $this->getFileCache()->save($type, $data);
- }
-
- return false;
- }
-
-
- function load($type) {
-
-
- if ($this->CONFIG->system_cache_enabled) {
- $cached_data = $this->getFileCache()->load($type);
-
- if ($cached_data) {
- return $cached_data;
- }
- }
-
- return null;
- }
-
-
- function enable() {
-
-
- _elgg_services()->datalist->set('system_cache_enabled', 1);
- $this->CONFIG->system_cache_enabled = 1;
- $this->reset();
- }
-
-
- function disable() {
-
-
- _elgg_services()->datalist->set('system_cache_enabled', 0);
- $this->CONFIG->system_cache_enabled = 0;
- $this->reset();
- }
-
-
- 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);
-
-
- $this->CONFIG->system_cache_loaded = true;
- }
-
-
- function init() {
- if (!$this->CONFIG->system_cache_enabled) {
- return;
- }
-
- 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->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));
- }
- }
- }
- }
|