Elgg  Version 1.9
/root/Elgg/engine/lib/cache.php

Get the URL for the cached fileThis automatically registers the view with Elgg's simplecache.

    $blog_js = elgg_get_simplecache_url('js', 'blog/save_draft');
elgg_register_js('elgg.blog', $blog_js);
elgg_load_js('elgg.blog');
Parameters
string$typeThe file type: css or js
string$viewThe view name after css/ or js/
Returns
string
Since
1.8.0
<?php
/* Filepath Cache */
static $FILE_PATH_CACHE;
if (!$FILE_PATH_CACHE) {
$FILE_PATH_CACHE = new ElggFileCache($CONFIG->dataroot . 'system_cache/');
}
return $FILE_PATH_CACHE;
}
$cache->clear();
}
if ($CONFIG->system_cache_enabled) {
return $cache->save($type, $data);
}
return false;
}
if ($CONFIG->system_cache_enabled) {
$cached_data = $cache->load($type);
if ($cached_data) {
return $cached_data;
}
}
return null;
}
datalist_set('system_cache_enabled', 1);
$CONFIG->system_cache_enabled = 1;
}
datalist_set('system_cache_enabled', 0);
$CONFIG->system_cache_enabled = 0;
}
/* Simplecache */
function elgg_register_simplecache_view($view_name) {
elgg_register_external_view($view_name, true);
}
// handle file type passed with view name
if (($type === 'js' || $type === 'css') && 0 === strpos($view, $type . '/')) {
$view = substr($view, strlen($type) + 1);
}
return _elgg_get_simplecache_root() . "$type/$view";
}
// stored in datalist as 'simplecache_lastupdate'
$lastcache = (int)elgg_get_config('lastcache');
} else {
}
return elgg_normalize_url("/cache/$lastcache/$viewtype/");
}
if (preg_match('~(?:^|/)(css|js)(?:$|/)~', $view, $m)) {
return $m[1];
} else {
return 'unknown';
}
}
return (bool) elgg_get_config('simplecache_enabled');
}
datalist_set('simplecache_enabled', 1);
elgg_set_config('simplecache_enabled', 1);
}
if (elgg_get_config('simplecache_enabled')) {
datalist_set('simplecache_enabled', 0);
elgg_set_config('simplecache_enabled', 0);
// purge simple cache
_elgg_rmdir(elgg_get_data_path() . "views_simplecache");
}
}
function _elgg_rmdir($dir) {
$files = array_diff(scandir($dir), array('.', '..'));
foreach ($files as $file) {
if (is_dir("$dir/$file")) {
_elgg_rmdir("$dir/$file");
} else {
unlink("$dir/$file");
}
}
return rmdir($dir);
}
if (!isset($CONFIG->views->simplecache) || !is_array($CONFIG->views->simplecache)) {
return false;
}
_elgg_rmdir("{$CONFIG->dataroot}views_simplecache");
mkdir("{$CONFIG->dataroot}views_simplecache");
$time = time();
datalist_set("simplecache_lastupdate", $time);
$CONFIG->lastcache = $time;
return true;
}
function _elgg_load_cache() {
$CONFIG->system_cache_loaded = false;
$CONFIG->views = new stdClass();
$data = elgg_load_system_cache('view_locations');
if (!is_string($data)) {
return;
}
$CONFIG->views->locations = unserialize($data);
$data = elgg_load_system_cache('view_types');
if (!is_string($data)) {
return;
}
$CONFIG->view_types = unserialize($data);
$CONFIG->system_cache_loaded = true;
}
function _elgg_cache_init() {
if (!defined('UPGRADING') && empty($CONFIG->lastcache)) {
$CONFIG->lastcache = (int)datalist_get('simplecache_lastupdate');
}
// cache system data if enabled and not loaded
if ($CONFIG->system_cache_enabled && !$CONFIG->system_cache_loaded) {
elgg_save_system_cache('view_locations', serialize($CONFIG->views->locations));
elgg_save_system_cache('view_types', serialize($CONFIG->view_types));
}
if ($CONFIG->system_cache_enabled && !$CONFIG->i18n_loaded_from_cache) {
foreach ($CONFIG->translations as $lang => $map) {
elgg_save_system_cache("$lang.lang", serialize($map));
}
}
}
elgg_register_event_handler('ready', 'system', '_elgg_cache_init');