diff options
author | Brett Profitt <brett.profitt@gmail.com> | 2011-10-29 15:08:34 -0700 |
---|---|---|
committer | Brett Profitt <brett.profitt@gmail.com> | 2011-10-29 15:08:34 -0700 |
commit | 3e4641537ff66b7e634f83e7a3386df9273ec9ff (patch) | |
tree | dde2ebe6125df0cc308dff3624c79f9b6a0b366b /engine | |
parent | 508000e9e3a49c0f659279ba916bde4a771ed777 (diff) | |
download | elgg-3e4641537ff66b7e634f83e7a3386df9273ec9ff.tar.gz elgg-3e4641537ff66b7e634f83e7a3386df9273ec9ff.tar.bz2 |
Fixes #4029, refs #3859. elgg_invalidate_simplecache() resets the lastcached and lastupdate datasets. Added documentation about how to use simple cache views.
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/cache.php | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/engine/lib/cache.php b/engine/lib/cache.php index 2bd3b2349..a6ebe2a30 100644 --- a/engine/lib/cache.php +++ b/engine/lib/cache.php @@ -129,7 +129,11 @@ function elgg_disable_filepath_cache() { * @warning Simple cached views must take no parameters and return * the same content no matter who is logged in. * - * @note CSS and the basic JS views are cached by the engine. + * @example + * $blog_js = elgg_get_simplecache_url('js', 'blog/save_draft'); + * elgg_register_simplecache_view('js/blog/save_draft'); + * elgg_register_js('elgg.blog', $blog_js); + * elgg_load_js('elgg.blog'); * * @param string $viewname View name * @@ -155,6 +159,9 @@ function elgg_register_simplecache_view($viewname) { /** * Get the URL for the cached file * + * @warning You must register the view with elgg_register_simplecache_view() + * for caching to work. See elgg_register_simplecache_view() for a full example. + * * @param string $type The file type: css or js * @param string $view The view name * @return string @@ -180,7 +187,7 @@ function elgg_get_simplecache_url($type, $view) { * * @warning This does not invalidate the cache, but actively resets it. * - * @param string $viewtype Optional viewtype to regenerate + * @param string $viewtype Optional viewtype to regenerate. Defaults to all valid viewtypes. * * @return void * @see elgg_register_simplecache_view() @@ -302,7 +309,8 @@ function elgg_disable_simplecache() { } /** - * Invalidates all cached views in the simplecache + * Deletes all cached views in the simplecache and sets the lastcache and + * lastupdate time to 0 for every valid viewtype. * * @return bool * @since 1.7.4 @@ -310,17 +318,35 @@ function elgg_disable_simplecache() { function elgg_invalidate_simplecache() { global $CONFIG; - $return = TRUE; + if (!isset($CONFIG->views->simplecache) || !is_array($CONFIG->views->simplecache)) { + return false; + } - if ($handle = opendir($CONFIG->dataroot . 'views_simplecache')) { - while (false !== ($file = readdir($handle))) { - if ($file != "." && $file != "..") { - $return = $return && unlink($CONFIG->dataroot . 'views_simplecache/' . $file); - } + $handle = opendir($CONFIG->dataroot . 'views_simplecache'); + + if (!$handle) { + return false; + } + + // remove files. + $return = true; + while (false !== ($file = readdir($handle))) { + if ($file != "." && $file != "..") { + $return = $return && unlink($CONFIG->dataroot . 'views_simplecache/' . $file); } - closedir($handle); - } else { - $return = FALSE; + } + closedir($handle); + + // reset cache times + $viewtypes = $CONFIG->view_types; + + if (!is_array($viewtypes)) { + return false; + } + + foreach ($viewtypes as $viewtype) { + $return = $return && datalist_set("simplecache_lastupdate_$viewtype", 0); + $return = $return && datalist_set("simplecache_lastcached_$viewtype", 0); } return $return; |