My polipo server is running on a fairly large drive and doesn't see much
use (I mostly use it as a caching proxy for the Debian repository so
that I don't download the packages for each and every machine), so
I haven't bothered to shrink its cache until now.  But over time, the
cache of course keeps growing and I'm now at the point where it
needs shrinking.  I looked at the doc and there doesn't seem to be
a standard "shrink the cache" program.

I think it would be good to bundle some sample shrink-the-cache script
along with polipo.  I'm not sure what you people use, but I've whipped
up the following script (this is run on an OpenWRT home router with 32MB
of RAM, which influenced the design and implementation significantly).
The script aims to throw out more or less the oldest half of the cache.


        Stefan


#!/bin/sh

cd /opt/var/cache/polipo

dirsize () {
    set -- $(echo * | wc)
    echo "$2"
}

dirshrink () {
    dirnb=$(dirsize)
    half=$(expr "$dirnb" / 2)
    ls -t | tail "-$half" | xargs rm -rf --
}

largest () {
    du -s * | sort -n | sed -n -e '$s/^[0-9]*[   ]*//p'
}

# First flush the oldest half of the web sites.
dirshrink
# If all sites use up the same amount of cache space, the above
# is all we need.  But if some sites use up a significantly larger
# fraction, then this may not be enough.           
# So look for the site using up the largest fraction of the space 
# and flush half of its content as well.
cd "$(largest)" && dirshrink


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Polipo-users mailing list
Polipo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/polipo-users

Reply via email to