a (more) general cache facility that is safe(r) memory-wise
Martin Pool
mbp at sourcefrog.net
Wed Jan 18 03:10:57 GMT 2006
On 16 Jan 2006, Denys Duchier <duchier at ps.uni-sb.de> wrote:
> Here is a module that implements a cache class where values can be kept live for
> N major collections. You create such a cache with:
>
> cache = Cache(N)
>
> you can add values to the cache as follows:
>
> ref = cache.put(val)
>
> cache.put(val) returns a "reference" to the value (like a weakref). You can
> test whether the reference is still valid with:
>
> ref.alive
>
> in which case you can retrieve the cached value with:
>
> ref.value
That looks like a nice interface and elegant implementation.
I just wonder if major collections are really the best way to express
how long things should persist? Would it perhaps be better to give a
limit on the number of objects retained in the cache?
--
Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060118/a44923f2/attachment.pgp
More information about the bazaar
mailing list