Autoflushing Elgg’s Simplecache

Ismayil Khayredinov
May 24 · 1 min read

Building plugins for Elgg can be a pain in the ass, because many changes require the cache to be flushed, which then takes ages to rebuild on a consecutive request. As a developer, you just spend hours waiting for the bloody thing. It doesn’t help that cacheable views are actually cached on the first request (cache is not rebuilt in its entirety), so an average site with a few dozens of AMD modules, CSS files and images, takes quite a while to load with a blank cache. Disabling cache is not really an option either, as things start timing out.

I got fed up, so I wrote a nodemon script that flushes the cache and rebuilds it fully, when changes are made in the mod directory.

  1. Install Nodemon
  2. Add a script definition to package.json

3. Create /scripts/reset.php

4. Create /scrpts/cache.php

Now you can run yarn dev and nodemon will watch for changes in mod and rebuild the cache, so you can preview your changes without having to go through the mental ordeal of flushing — waiting — fixing a typo — flushing — waiting.

Written by

Wheels keep on turning, planet keeps on burning.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade