1

Topic: Cache questions

Hello,

We recently purchased Image & Filemanager, and it is functioning quite well.

I'm about to finish incorporating tinyMCE3 and the Image & Filemanager into our CMS. However I'm a little puzzled on finding a means to avoid the browser cache when desired.

Of course the browser should cache as much as possible for performance reasons,  I utilize the tinymce_gzip.php?version=xxx variant to get this done properly.
This way, when upgrading to a new tinyMCE version the changed version param in the query string will trigger the clients browser to download the new JS code.
But what if the new version contains changes to .html / image files? These might still be cached by said browser.
Is it up to me to never let those files get cached? That's doable, but would hurt performance.

This also applies to Imagemanager & Filemanager.

Furthermore, if in Imagemanager an image is edited (i.e. cropped), and saved with the same filename it will remain cached as well. Thus no difference will be seen in advimg, or in the editor.
Could avoid this by not letting those images get cached at all, but maybe the Image manager could force (or default to) saving the image to a new filename? Then there would not a be cache problem.

2

Re: Cache questions

I think the best way is to use directories instead using mod_rewrite or similar since you could then just point everything to. /<version>/imagemanager where <version> is a dynamic path/virtual directory.

Best regards,
Spocke - Main developer of TinyMCE

3

Re: Cache questions

spocke wrote:

I think the best way is to use directories instead using mod_rewrite or similar since you could then just point everything to. /<version>/imagemanager where <version> is a dynamic path/virtual directory.

Thanks spocke, seems to be a working solution!
Please note that one does have to edit tiny_mce_gzip.php:

$buffer = "var tinyMCEPreInit={base:'" . dirname($_SERVER["SCRIPT_NAME"]) . "',suffix:''};";

the base variable should be changed to that of the virtual directory.


Do you have any solution to the aforementioned Imagemanager cache problem? (Editing images and saving them with the same filename will get them cached, thus changes not visible.. Not really an Imagemanager bug, but it is probably the best place to workaround the cache)


chummino wrote:

I tried that, but mod_rewrite does not work for me. Any other way to do it?

What doesn't work for you exactly? Appears to work fine here, but tests are still on the way

Last edited by kevinversteeg (2012-02-14 11:23:41)

4

Re: Cache questions

Not sure how to fix the image cache bug. Have tired various fixes for that one. But it could be fixed server side if you use etags for caching however it would produce more requests to the server since it will then do a HEAD request to compare the etag.

Best regards,
Spocke - Main developer of TinyMCE

5

Re: Cache questions

Yes, seems quite hard to fix

1. no hard caching (using your method with ETags or similar approach with If-Modified-Since etc)
2. (semi-)automatically updating the filename after image has been edited. This could be done by the Imagemanager. Filename could be appended with version, i.e. original is 'tinyMCE.jpg', cropping&saving image will create 'tinyMCE_v1.jpg'.

#2 is not very elegant, but maybe a description could be added to the save img dialogue where this behaviour is explained
#1 is less obtrusive, but if you're editing content with 10 images (not that uncommon) it would indeed cost 10 HTTP requests every time the page is reloaded

6

Re: Cache questions

Yeah, some option to generate version copies are probably the way to go.

Best regards,
Spocke - Main developer of TinyMCE

7

Re: Cache questions

Spocke, I may have misjudged the no cache option. It seems IE9 will not instantly refresh an image with the same filename, regardless of cache. Even if you set the browser cache settings to "Every visit to the page".

That makes me believe it might be an editor related problem.
Steps to reproduce are fairly simple:
1. Insert image into editor
2. Edit it (crop / resize or whatever), save with same filename, insert into editor and observe no difference

Unfortunately I cannot test this on the tinymce website demo because the Imagemanager is set to demo mode.

Can you reproduce this or am I overlooking something?

8

Re: Cache questions

This one is tricky there is no way a JS client can clear the cache for a specific file. The only way could be to configure the server to use ETags for static files but it would require an extra request form the server since it would have to send an HEAD request to see if the image is updated or not.

You could just save the image as a new image name and it won't be cached.

Best regards,
Spocke - Main developer of TinyMCE

9

Re: Cache questions

Yes spocke, that's why I'm attempting the ETag headers 'fix'.

But like I said, unfortunately, even that does not seem to work.
Even configuring IE's cache settings to "Every visit to the page" does not fire a new HTTP request for said image.

With that setting IE should reload the image right? But it doesn't, that's why I think it might be an editor related problem?


(I know changing the filename will ofcourse fix the problem, but I'm afraid people will forget to do so)

10

Re: Cache questions

You need to make sure you don't send out an date header as well as an etag. Since I think some browsers will then cache it until the date expires then compare the etag.

The new image should load if you clear the cache. However I might be cached in memory if no page was "reloaded".

Best regards,
Spocke - Main developer of TinyMCE

11

Re: Cache questions

Well, I do send date/expires headers (expire after 1 second), that in combination with IE's "Every visit to the page" cache settings (meaning it should not cache anything).

It's probably cached in memory, when the page is reloaded the image is instantly refetched.

When you select the image in Imagemanager, it appears in the advimg popup with the cached version (probably in memory then).

You don't experience this behaviour spocke? It should be fairly easy to reproduce.

12

Re: Cache questions

Yes, I can not much we can do about it though since there is no way to clear the memory cache for an image a.f.a.i.k. So saving the image as a new unique name might be preferred or adding some random number in the query string. Like img.jpg?r=123 but that would prevent proper caching if the image is reused on multiple pages.

Best regards,
Spocke - Main developer of TinyMCE