2010/4/13 Intransition <transfire / gmail.com>:
>
>
> On Apr 13, 1:28 ¨Βν¬ ΓαμεΓμαυσεΌφιλλ®®®ΐηναιμ®γονχςοτεΊ
>> On 4/13/10, Intransition <transf... / gmail.com> wrote:
>>
>> > will mean that @foo be GC'd when the object is GC'd, but if I do
>>
>> > FOO = []
>>
>> > def foo
>> > FOO[object_id] ||= something
>> > end
>>
>> I have to assume that you meant FOO to be a hash... tho an array will
>> work here... sorta.
>>
>> But rather than either an array or hash, what if you could write:
>>
>> FOO=Cache.new
>>
>> That is, FOO would behave mostly like a hash, but unused entries would
>> age out after a while. Now if only someone would invent an appropriate
>> Cache class.
>
> Ah, very good thought! An LRUCache would do pretty well here.
>
> Well then, that leads to me to another project. My implementation of
> LRUCache (lrucache gem) kind of sucks in that it only handles max
> size, so I am looking for a new one to replace it. Any
> recommendations?

What else do you want to handle?  My implementation [1] does also only
consider size but I have also seen implementations that consider
insertion or access time.  Personally I dislike those solutions
because they might throw away stuff too early and make the
implementation more complex.  The main point (resource control) is
already achieved by limiting the size of a LRU map.

Kind regards

robert

http://github.com/rklemme/muppet-laboratories/blob/master/lib/lruhash.rb


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/