generic cache manager?

Michael McDaniel erlang@REDACTED
Tue Dec 20 18:25:38 CET 2005


On Tue, Dec 20, 2005 at 04:55:06PM +0400, Gaspar Chilingarov wrote:
> Hi there!
> 
> Are there any module, which provides generic caching functions --
> with ability to do positive and negative hit caching?
> 
> For example, I have several modules which fetch data from remote nodes, and I
> wish to cache call results for a some time.
> 
> I've looked in jungerl, but found nothing, may be I'm missing something?
> 
> -- 
> Gaspar Chilingarov
> System Administrator
> 
> t +37491 419763
> w www.netter.am
> e nm@REDACTED
> 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Not exactly generic, but a basic version of what I do is below.
I only need one day granularity; that is easily adjusted if needed.

I store the results in mnesia along with a calendar:universal_time()
date.

To check how old a new candidate is, I use


1) Lookup candidate in mnesia and if found, check date with
   old/1 (below).
2) If candidate is not in mnesia, it is stale; insert it for
   next time.


old(Date) ->

 F = #freshness{} ,

 T1 = calendar:datetime_to_gregorian_seconds(calendar:universal_time()) ,
 T2 = calendar:datetime_to_gregorian_seconds( Date ) ,

 OneDayOfSeconds = 86400 ,

 if ((T1 - T2) / OneDayOfSeconds) > F#freshness.maxdays ->
	  stale ;
 true ->  fresh
 end
.


Maybe distributed mnesia would work for your application and
then the fresh/stale test could be done on each node.



~Michael

-- 
Michael McDaniel
Portland, Oregon, USA
http://autosys.us
+1 503 283 5284



More information about the erlang-questions mailing list