]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #4029, refs #3859. elgg_invalidate_simplecache() resets the lastcached and...
authorBrett Profitt <brett.profitt@gmail.com>
Sat, 29 Oct 2011 22:08:34 +0000 (15:08 -0700)
committerBrett Profitt <brett.profitt@gmail.com>
Sat, 29 Oct 2011 22:08:34 +0000 (15:08 -0700)
engine/lib/cache.php

index 2bd3b2349c561fb0aa683c8581339d70222f3dc7..a6ebe2a301846ebef951087dc3bc71a4fbfdf09d 100644 (file)
@@ -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;