Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » How do you disable the cache?

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

Page: 1
Go to End
Author Topic: 2770 Views
  • BlueScreen
    Avatar
    Community Member
    36 Posts

    How do you disable the cache? Link to this post

    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!

  • BlueScreen
    Avatar
    Community Member
    36 Posts

    Re: How do you disable the cache? Link to this post

    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

  • BlueScreen
    Avatar
    Community Member
    36 Posts

    Re: How do you disable the cache? Link to this post

    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?

  • lerni
    Avatar
    Community Member
    80 Posts
  • BlueScreen
    Avatar
    Community Member
    36 Posts

    Re: How do you disable the cache? Link to this post

    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);

  • BlueScreen
    Avatar
    Community Member
    36 Posts

    Re: How do you disable the cache? Link to this post

    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

  • PanPipes
    Avatar
    Community Member
    1 Post

    Re: How do you disable the cache? Link to this post

    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.

    2770 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.