1

Topic: Funky Cache - Quick review and questions

I have been using Funky Cache plugin in the last 3 days and I like it as it works great with my Nginx as I wanted to.

I set "Cache file suffix" = ".html' and "Cache folder" = "/cache". I think that is the default settings. But I use Nginx rewrite below as I think it is more efficient than the one suggested on the "Example rewrite rules".

                location = / {
                        try_files /cache/index.html @wolfcms;
                }

                location / {
                        try_files /cache$request_uri @wolfcms;
                }

                location @wolfcms {
                        rewrite ^/(.*)$ /index.php?WOLFPAGE=$1 break;
                        include fastcgi_params;
                }

One thing I don't understand is that, why the plugin unnecessarily creates empty folder for cache file located on nested folders like below?

root@myvps:/wolfcms_0.8.0/cache/articles/2014/06/01# ls -ltr
total 16
drwxr-xr-x 2 www-data www-data 4096 Jun  3 20:06 my-second-article
-rw-r--r-- 1 www-data www-data 3033 Jun  3 20:06 my-second-article.html
drwxr-xr-x 2 www-data www-data 4096 Jun  3 20:10 my-first-article
-rw-r--r-- 1 www-data www-data 3084 Jun  3 20:10 my-first-article.html
root@myvps:/wolfcms_0.8.0/cache/articles/2014/06/01# ls -ltr my-second-article my-first-article
my-second-article:
total 0

my-first-article:
total 0
root@myvps:/wolfcms_0.8.0/cache/articles/2014/06/01#

Could anybody explain the reason for that?

The other thing is, I think it would be better if the plugin also creates the compressed version of the cached file. For instance after generating my-first-article.html it also generates my-first-article.html.gz, so that the web server (Nginx in my case) does not need to perform the compression on the fly while serving the requests. For heavy load servers, I think the performance improvement would be quite significant as the web server does not need to do unnecessary processing for every requests.

Where can I raise enhancement requests? Should I do that on https://github.com/mvdkleijn/funky_cache/issues/new?

Thanks in advance for your response.

Thumbs up

2

Re: Funky Cache - Quick review and questions

Martijin is responsible for that plugin so it's best to open an issue on github with link to this thread.

Tutorials at Project 79 | Wolf CMS Docs

3

Re: Funky Cache - Quick review and questions

Thanks Jackie.

I have just raised the following tickets on Github against Funky Cache:

https://github.com/mvdkleijn/funky_cache/issues/5
https://github.com/mvdkleijn/funky_cache/issues/6

Thumbs up

4

Re: Funky Cache - Quick review and questions

There is actually additional issue related to https://github.com/mvdkleijn/funky_cache/issues/5. I can not have empty URL_SUFFIX in config.php, because there will be no cached file being generated.

I really would like to help in providing the patch for this. But a part from I don't know exactly how Funky Cache works, my knowledge in PHP coding is quite limited. Could you please give me some hints to try to fix this?

Thumbs up

5

Re: Funky Cache - Quick review and questions

I just started to "cannibalise" Funky Cache plugin.

It looks that I have managed to get some functionalities that I want working:
1. Remove unnecessary creation of empty folders
2. Remove dependency on URL_SUFFIX setting

The only requirement is that, the URL rewrite on the web server (Nginx in my case) should follow "Cache file suffix" setting. The URL_SUFFIX setting is only being used on all available links on the pages. The actual cached file will be set to have the "Cache file suffix".

Before I submit my patch to Github, I thought it would be better to post it here for everybody to review, especially that I am quite a beginner on Wolf CMS and PHP coding. I really appreciate your feedback on my patch below.

diff -ruN '--exclude=.git' funky_cache_github/index.php funky_cache_mine/index.php
--- funky_cache_github/index.php        2014-06-03 20:32:19.466198913 +0200
+++ funky_cache_mine/index.php  2014-06-07 22:34:15.159742323 +0200
@@ -100,14 +100,14 @@

     function funky_cache_create($page) {
         if ($page->funky_cache_enabled) {
-            $data['url'] = URI_PUBLIC.CURRENT_URI.URL_SUFFIX;
+            $data['url'] = URI_PUBLIC.CURRENT_URI;

             // Correct URL for frontpage - should become index.html
-            if ($data['url'] == URI_PUBLIC.URL_SUFFIX) {
-                $data['url'] = URI_PUBLIC.'index'.funky_cache_suffix();
+            if ($data['url'] == URI_PUBLIC) {
+                $data['url'] = URI_PUBLIC.'index';
             }

-            $data['url'] = funky_cache_folder().$data['url'];
+            $data['url'] = funky_cache_folder().$data['url'].funky_cache_suffix();
             $data['url'] = preg_replace('#//#', '/', $data['url']);
             $data['page'] = $page;

diff -ruN '--exclude=.git' funky_cache_github/models/FunkyCachePage.php funky_cache_mine/models/FunkyCachePage.php
--- funky_cache_github/models/FunkyCachePage.php        2014-06-03 20:32:19.466198913 +0200
+++ funky_cache_mine/models/FunkyCachePage.php  2014-06-07 22:58:45.889075874 +0200
@@ -52,19 +52,9 @@
         $file = array_pop($parts);

         /* If deep link create directories when needed. */
-        $dir = '';
-        foreach ($parts as $part) {
-            if (!is_dir($dir .= "/$part")) {
-                mkdir($dir);
-            }
-        }
-        /* Fix case when articles.html is created before articles/ */
-        /* TODO This still creates on extra directory in the end.  */
-        if (('archive' == $this->page->behavior_id) || ($this->page instanceof PageArchive)) {
-            $dir .= '/'.basename($file, funky_cache_suffix());
-            if (!is_dir($dir)) {
-                mkdir($dir);
-            }
+        $dir = '/' . implode('/',$parts);
+        if (!is_dir($dir)) {
+           mkdir($dir,0755,true);
         }
         return file_put_contents($this->path(), $this->content(), LOCK_EX);
     }

Thumbs up

6

Re: Funky Cache - Quick review and questions

I never used this plugin but I you might find this topic interesting to read.

I know from past that there were some issues with mod_rewrite and funky cache but not sure that it was solved.

Tutorials at Project 79 | Wolf CMS Docs

7

Re: Funky Cache - Quick review and questions

Thanks Jackie,

I have read that discussion. I think the problems with the rewrite only happens on Apache. As from the first second I installed the plugin and set the rewrite on Nginx, I do not have any problems.

By the way, there is a DEBUG switch. How do we use that? I tried to set that to true in the config.php, but I don't see anything on my web browser. I think I should see "Cache miss" generated by Funky Cache.

Cheers,

Anto

Thumbs up

8

Re: Funky Cache - Quick review and questions

If everything is ok then you should not see anything smile

DEBUG set to "On" shows PHP errors, mostly. Or nothing, meaning "white screen" if something is not working properly. I use this only locally. When site goes live I turn it off.

Tutorials at Project 79 | Wolf CMS Docs

9

Re: Funky Cache - Quick review and questions

I have just forked Martijn's code on Github into https://github.com/anto/funky_cache. I will do my changes there instead of bugging Martijn, because my changes might not be applicable for everyone.

I have applied the 2 changes I mentioned above. And with the help of the internet, I will try to implement the following:
1. Generate the compressed version of the cached files
2. Prevent clearing all cached files when only one page is being updated

I think the first one looks quite easy, but the second one will be a challenge for me.

Notes:
Edited the broken github URL

Last edited by anto (2014-06-08 11:24)

Thumbs up

10

Re: Funky Cache - Quick review and questions

I just updated my github to include the changes for generating (and deleting) the compressed version of the cached file.

It took me a while to understand how to safely add and delete both cached files. It turned out to be quite simple (and safe I hope).

Thumbs up

11

Re: Funky Cache - Quick review and questions

Now you can make a pull request to the original. And perhaps we can test your on Apache to see if it's working like on nginx.

Tutorials at Project 79 | Wolf CMS Docs

12

Re: Funky Cache - Quick review and questions

Hello Jackie,

I used Apache once long time ago. I had difficulties with the configuration and it uses too much of my server resources, especially the CPU and RAM. I hate it to my bone since then and I switched to Lighttpd. Then I saw that it is easier to configure Nginx and it is more efficient. It becomes my favourite web server and even more with PHP-FPM became mature.

For those who would like to try Funky Cache plugin on my github with Nginx, the required Nginx modules are gzip and gzip_static. I have the "Cache file suffix" = ".html' and "Cache folder" = "/cache/" on Funky Cache plugin settings. You can use any URL_SUFFIX on your config.php. The following is the relevant Nginx configuration on my setup.

        gzip on;
        gzip_http_version 1.1;
        gzip_buffers 16 8k;
        gzip_comp_level 6;
        gzip_min_length 0;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.(?!.*SV1)";
        gzip_static on;

                location = / {
                        try_files /cache/index.html @wolfcms;
                }

                location / {
                        try_files /cache$request_uri.html @wolfcms;
                }

                location @wolfcms {
                        include fastcgi_params;
                        rewrite ^/(.*)$ /index.php?WOLFPAGE=$1 break;
                }

Please do not ask me about how to convert that to Apache, because as above I know very little of Apache configuration.

I usually use YSlow or Page Speed to test the caching function.

Cheers,

Anto

Last edited by anto (2014-06-08 21:54)

Thumbs up

13

Re: Funky Cache - Quick review and questions

anto wrote:

By the way, there is a DEBUG switch. How do we use that? I tried to set that to true in the config.php, but I don't see anything on my web browser.

I sometimes put:

error_reporting(1);
ini_set('display_errors', 1);

in index.php. It works for me.

Thumbs up

14

Re: Funky Cache - Quick review and questions

As for Funky Cache,

can some one tell me, how it cached 3 Czech pages?
I have page in slo and eng language.

PunBB bbcode test

Last edited by BigBug (2017-04-28 20:07)

Thumbs up