https://gist.github.com/eproxus/d74315864fd6897bb47741e8de5b...
The example is a bit Erlang specific but the cache action it contains is quite generic.