On 17 April 2014 10:26, Norbert Hartl <norb...@hartl.name> wrote:

> While looking at the code in voyage I got to WeakValueDictionary as voyage
> uses it as object cache. If I looked correctly the WeakValueDictionary is
> based on equality and not identity. Is that correct? Feels wrong!
>
>
well, comparison used for keys..
and i agree that for caching, an identity comparison makes much more sense,
since you want it to be fast, and identity comparison is no doubt faster
than
equality comparison, especially if keys are complex objects which implement
equality based on comparing own fields.

but for that, i think we would need new kind of dictionary, e.g.
WeakValueIdentityKeyDictionary (or some similar name).

Btw, for caching i prefer to use round-robin cache with limited size
(like that cache never grows too big, and instead simply drops/overrides
existing entries when it become full).. this helps maintaining cache size
under control.

A good example is LRUCache, which is very suitable method to cache
objects.. albeit at cost of some extra processing for accessing it.


> Norbert
>

-- 
Best regards,
Igor Stasenko.

Reply via email to