[Pharo-project] What the best way to implement week dictionary cache
Hello. I want implement cache for proxy objects. I need some kind of dictionary which I can request for proxy of actual object. And any user of actual objects will work with same instances of proxies. And every proxy object has reference to actual object. Obvious solution is basic dictionary with actual objects as keys and proxy-objects as values. But next I want my dictionary be week. And when nobody uses actual object it should be garbaged and my cache of proxies should be cleaned from unused proxies/actuals. Is it possible to implement such cache? And how it can be done? Best regards, Denis
On 27 November 2012 07:56, Denis Kudriashov <dionisiydk@gmail.com> wrote:
Hello.
I want implement cache for proxy objects. I need some kind of dictionary which I can request for proxy of actual object. And any user of actual objects will work with same instances of proxies. And every proxy object has reference to actual object.
Obvious solution is basic dictionary with actual objects as keys and proxy-objects as values. But next I want my dictionary be week. And when nobody uses actual object it should be garbaged and my cache of proxies should be cleaned from unused proxies/actuals.
Is it possible to implement such cache? And how it can be done?
You could take a look at the WeakDictionary that ships in a standard Squeak image, if there isn't already one lying around in Pharo. There are several classes using weak references. frank
Best regards, Denis
did you look at Ghost? Because mariano worked during one year on it. Stef On Nov 27, 2012, at 8:56 AM, Denis Kudriashov wrote:
Hello.
I want implement cache for proxy objects. I need some kind of dictionary which I can request for proxy of actual object. And any user of actual objects will work with same instances of proxies. And every proxy object has reference to actual object.
Obvious solution is basic dictionary with actual objects as keys and proxy-objects as values. But next I want my dictionary be week. And when nobody uses actual object it should be garbaged and my cache of proxies should be cleaned from unused proxies/actuals.
Is it possible to implement such cache? And how it can be done?
Best regards, Denis
You could take a look at the WeakDictionary that ships in a standard Squeak image, if there isn't already one lying around in Pharo. There are several classes using weak references.
I will look at squeak stuff. But my question more about about conceptual problem: I need week dictionary which values has reference to it key. Can it be really week? I think it can be kind of "ephemeron problem" and such dictionary contents will never be garbaged. Is ephemerons supported by latest vm? In pharo I see two classes: WeakKeyDictionary and WeakValueDictionary. What you think I should use to implement my requirements: cache which can be cleaned by garbage collector due to weak keys or values? 2012/11/27 Stéphane Ducasse <stephane.ducasse@inria.fr>
Ghost
I think it is just implementation of very skin proxy objects? Is it related to weak dictionary cache?
On 27 November 2012 11:11, Denis Kudriashov <dionisiydk@gmail.com> wrote:
You could take a look at the WeakDictionary that ships in a standard Squeak image, if there isn't already one lying around in Pharo. There are several classes using weak references.
I will look at squeak stuff. But my question more about about conceptual problem: I need week dictionary which values has reference to it key. Can it be really week? I think it can be kind of "ephemeron problem" and such dictionary contents will never be garbaged. Is ephemerons supported by latest vm?
Ephemerons support is in VM. All you need is to load image-side code. http://code.google.com/p/cog/issues/detail?id=44 I plan to change implementation to use separate object format id. But if you need it right now, you can use them in current state.
In pharo I see two classes: WeakKeyDictionary and WeakValueDictionary. What you think I should use to implement my requirements: cache which can be cleaned by garbage collector due to weak keys or values?
2012/11/27 Stéphane Ducasse <stephane.ducasse@inria.fr>
Ghost
I think it is just implementation of very skin proxy objects? Is it related to weak dictionary cache?
-- Best regards, Igor Stasenko.
participants (4)
-
Denis Kudriashov -
Frank Shearar -
Igor Stasenko -
Stéphane Ducasse