Removing cache after shell script is done
Posted by primeminister | Filed under bash, Cake-Toppings
I have a scraper that runs every 6 hours and adds reviews, audio and video of the found music artists to our database. The problem is that I wanted to cache elements and views for minimum of 1 day and let the scraper remove the cache when it found new items.
Firts of all I use file caching. I tried with Clear::cache(false); at the end of the shell script but that didn’t work. I guess the file list is too long.
The I had a simple bash script that just stated
rm -f tmp/cache/views/element*
But the list was too long and it give ‘Argument too long‘ warnings. Then I had a look on the internet (Wait… what is that?) and created my own long-list-removable-view-files-bash-script:
#! /usr/bin/bash find ./tmp/cache -name 'cs_*' | xargs rm -f find ./tmp/cache -name 'cake_*' | xargs rm -f find ./tmp/cache/models -name 'cake_*' | xargs rm -f find ./tmp/cache/models -name 'musicbrainz_*' | xargs rm -f find ./tmp/cache/persistent -name 'cake_*' | xargs rm -f find ./tmp/cache/views -name 'element_*' | xargs rm -f
It does not only views removal, but I use this script also for new release deployment.
After I had finished this @savant pointed me to the PDF Math Curry where he pointed out the same… Damn!! :)
August 12th, 2009 at 01:59
find ./tmp/cache/views -name ‘element_*’ -delete
August 12th, 2009 at 07:25
@dardo: Also possible but I thought ‘find’ will do that -delete for each file found. If you have a lot (10k) files it will take a while.