Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

How do you disable the cache?


Reply


7 Posts   2958 Views

Avatar
BlueScreen

Community Member, 36 Posts

14 April 2011 at 10:15am

Edited: 14/04/2011 10:18am

Lately silverstripes cache has become a problem, especially as my site has become more and more dynamic and interactive and needs to make numerous API calls to keep its information dynamic

For some reason ?flush=1 does not work anymore, I have to clear the cache manually or else every page refresh acts as though nothing has changed.

Secondly the cache wont let me run an API call twice in a row, it saves the first one then recalls data from the cache each time that call is run again. This is a major pain in the ass when data has changed and a new API call for the same item is needed in order to display the updated information

I don't know the cache became this aggressive. How do I limit what silverstripe tries to cache if not turn it off completely?

I am aware of partial caching and it looks like what I need, but it appears that partial caching specifies what to cache as opposed as what not to cache. I need to tell silverstripe what not to cache. Help!

Avatar
BlueScreen

Community Member, 36 Posts

14 April 2011 at 11:44am

I tried to see if I could use PHP to delete all the cache files:

      $handler = opendir($_SERVER['DOCUMENT_ROOT']."/silverstripe-cache");
         if($handler){
            while ($file = readdir($handler)) {
               if ($file != "." && $file != "..") {
            unlink($file);
            }
         }
         }
      closedir($handler);


but I keep getting an error where the unlink() function claims that the cache files that it is given do not actually exist. Perhaps because all of those cache files fail the is_file() function due to having unusual names

Avatar
BlueScreen

Community Member, 36 Posts

18 May 2011 at 2:54pm

Sorry to bump an old thread but this is a really hard problem and I am sure there is a simple solution. I just don't know it >.<

I believe the cached data is being stored in the cache files that start with 'xmlresponse_' inside the silverstripe cache folder. They store the results that the web app gets back from the server and the app then re-uses those files. I suspect this because a new one gets made for each new call to the server and deleting the files results in longer load times when making calls to the server

I have a function that deletes those xmlresponse files...it seems to work if nothing has really changed in the data that the server passes...but when something has changed in the server data the response turns up as a null value!

I can't figure out why Silverstripe would behave this way but I think a lot of this trouble can be avoided if silverstripe DIDN'T try to stockpile the xmlresponse files in the first place, how do you tell it to stop?

There must be some way to make silverstripe NOT cache things, somebody here must know...right?

Avatar
lerni

Community Member, 80 Posts

18 May 2011 at 6:04pm

hi bluescreen
[url]http://api.silverstripe.org/2.4/sapphire/core/SS_Cache.html[/url]

hope this helps
lukas

Avatar
BlueScreen

Community Member, 36 Posts

23 May 2011 at 1:36pm

Thanks lerni, I spotted this:

SS_Cache::set_cache_lifetime('any', -1, 100);


and added it to my mysite config file but unfortunately the caching still occurs.

I looked at the code that creates those xmlresponse files that I want to get rid of; it's in RestfulService.php

      $cachedir = TEMP_FOLDER;   // Default silverstripe cache
      $cache_file = md5($url);   // Encoded name of cache file
      $cache_path = $cachedir."/xmlresponse_$cache_file";

If I comment this out (and its references in the function) then the API calls do not get cached. This is exactly what I want to happen!

I can't do it that way of course because it involves hacking an original silverstripe core file and that is a big no-no. There needs to be some kind of silverstripe configuration I can make to change it

Sadly it looks like there are no checks in place that allow the code to proceed without caching the xmlresponse files so there must not be any kind of configuration I can make. Giving the xmlresponse cache files a lifetime of -1 sounds like the way to go.

So can anyone see why this doesn't work:

SS_Cache::set_cache_lifetime('any', -1, 100);

Avatar
BlueScreen

Community Member, 36 Posts

23 May 2011 at 1:58pm

Edited: 23/05/2011 5:13pm

Okay, I think what I need to do is decorate RestfulService.php so that I have my own version of the API request function and exclude the code that creates xmlresponse files in my own copy.

So the question now turns towards decorating the RestfulService.php file.

[Edit]

Scratch that, it's the expiry parameter in RestfulService.php that I am after. It needs to be set to -1. That causes the xmlresponse file that is created to be overwritten and never loaded

Avatar
PanPipes

Community Member, 1 Post

1 August 2013 at 3:32am

Hey BlueScreen,

I know this post is a while old, and this might not be helpful for older versions of Silverstripe, but if you see here:
http://devincharge.com/disabling-cache-silverstripe/ you should pass 'default' not 'any'. I believe 'any' is a mistake in the docs, as there is no reference to it in the actually code.

Cheers,

PanPipes.