Choose your SilverStripe cache location carefully
Let me begin today's lesson in the world of SilverStripe with an explanation of my usage. This site is currently hosted on a shared host, it is cheap, has all I need and I am not expecting a high volume of viewers at any one time. This suits my usage perfectly. In fact, any of my smaller work tends to be on shared hosts. The problem I have had with shared hosts is that you never quite know how they are configured until you have access to them. Some use PHP 5.3, others 5.2 but allow you to choose a different version, some even more rubbish ones are still back in the stone age of PHP 4. Even then, some are missing various Apache modules that are just, what I call, must haves and others, dare I say it use Microsoft IIs, which is a pile of stinky turd. All that said, I found that the host I am on, works with SilverStripe 3 just perfectly ... or so I thought.
So I have been fiddling with my site, making some adjustments so it handles mobile and handheld screens much better and some much appreciated feedback from friends. This has meant some CSS changes and occasionally adjustments to the templates. Provided I am logged in, a simple flush and all is fine. Until the other night ...
The weirdness begins
Then I am editting the article and some of the popups from the TinyMCE editor are very slow to load, if at all. The links button brings up an nearly empty popup. The images button has errors when I paginate between images in a folder. Luckily at this point I notice that the error coming back is to do with a template located in the host's temporary directory, the default location SilverStripe will put it's caches for manifest, templates and the like. Something is not right at that location.
At the mercy of shared locations
I remember that you can explicitly set the location of the silverstripe cache by simply creating a directory called silverstripe-cache at the same level as the modules directories. I do that, flush=all and it builds beautifully into this new local silverstripe-cache. All problems have seemed to have fixed, in fact, performance of the site seems to have gotten better. What the deuce was happening into the global temporary directory? I haven't a clue, I can't access it, and that is the problem!
So where is the mythical system temporary directory? Was it full? Was some other website spewing rubbish it? Was it split over on another virtual machine and some weirdness of previous versions being used? I haven't a clue and honestly, I don't care.
Lesson of the story
If you are on a shared host, explicitly set your cache directory by placing an empty directory at the same level as your modules. Ensure it is writable to the same user that your website will run as. The htaccess file, provided you haven't tampered with it, has protection to stop direct access to it:
<IfModule mod_alias.c> RedirectMatch 403 /silverstripe-cache(/|$) </IfModule>
You can also explicitly define the location in your _ss_environment.php file:
Either way you do it, I suggest doing it when using a shared host to avoid being subject to whims of the system temporary directory. May save you a lot of swearing and WTF moments.