Elgg  Version 1.11
/root/Elgg/engine/classes/Elgg/Cache/SimpleCache.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
<?php
namespace Elgg\Cache;
class SimpleCache {
private $CONFIG;
public function __construct() {
global $CONFIG;
$this->CONFIG = $CONFIG;
}
function registerView($view_name) {
elgg_register_external_view($view_name, true);
}
function getUrl($type, $view) {
// 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";
}
function getRoot() {
// stored in datalist as 'simplecache_lastupdate'
$lastcache = (int)_elgg_services()->config->get('lastcache');
} else {
$lastcache = 0;
}
return elgg_normalize_url("/cache/$lastcache/$viewtype/");
}
function isEnabled() {
return (bool) _elgg_services()->config->get('simplecache_enabled');
}
function enable() {
_elgg_services()->datalist->set('simplecache_enabled', 1);
_elgg_services()->config->set('simplecache_enabled', 1);
}
function disable() {
if (_elgg_services()->config->get('simplecache_enabled')) {
_elgg_services()->datalist->set('simplecache_enabled', 0);
_elgg_services()->config->set('simplecache_enabled', 0);
// purge simple cache
_elgg_rmdir(_elgg_services()->config->getDataPath() . "views_simplecache");
}
}
function invalidate() {
if (!isset($this->CONFIG->views->simplecache) || !is_array($this->CONFIG->views->simplecache)) {
return false;
}
_elgg_rmdir("{$this->CONFIG->dataroot}views_simplecache");
mkdir("{$this->CONFIG->dataroot}views_simplecache");
$time = time();
_elgg_services()->datalist->set("simplecache_lastupdate", $time);
$this->CONFIG->lastcache = $time;
return true;
}
function init() {
if (!defined('UPGRADING') && empty($this->CONFIG->lastcache)) {
$this->CONFIG->lastcache = (int)_elgg_services()->datalist->get('simplecache_lastupdate');
}
}
}