Autoflushing Elgg’s Simplecache
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.
- Install Nodemon
- 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.