# Weakrefs and object caching

**URL:** <https://www.ruby-forum.com/t/weakrefs-and-object-caching/71100>\
**Category:** Ruby\
**Created:** [October 5, 2006, 10:24am UTC](https://www.ruby-forum.com/t/weakrefs-and-object-caching/71100 "2006-10-05T10:24:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tele](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ba0ec/32.png) [@tele](https://www.ruby-forum.com/u/tele)\
**Post date:** [October 5, 2006, 10:24am UTC](https://www.ruby-forum.com/t/weakrefs-and-object-caching/71100/1 "2006-10-05T10:24:12Z")

</div>

Hi,

i need to memorize in a Cache some object that i identify through a  
attribute my\_id.  
base on some event i update the attributes of the objects in the cache  
and when the processing is done i can remove the object from cache.

I found some solution:

The memoizable library that can serialize/deserialize object in memory  
or in a file.

then the Weakrefs of ruby stdlib, in particular i’ve found this link:

[http://eigenclass.org/hiki.rb?weakhash+and+weakref](http://eigenclass.org/hiki.rb?weakhash+and+weakref)

For performance reasons and whatever what do you advise me to do?  
examples,solutions, useful link?

thank you

:tele

---

<div class="post-metadata">

**Author:** ![tele](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ba0ec/32.png) [@tele](https://www.ruby-forum.com/u/tele)\
**Post date:** [October 5, 2006, 3:14pm UTC](https://www.ruby-forum.com/t/weakrefs-and-object-caching/71100/2 "2006-10-05T15:14:46Z")

</div>

On Oct 5, 2006, at 3:22 AM, tele wrote:

> For performance reasons and whatever what do you advise me to do?  
> examples,solutions, useful link?

I wrote a fair amount about memoization in this blog post, including  
a full implementation and a weak reference cache:

[http://blog.grayproductions.net/articles/2006/01/20/caching-and-](http://blog.grayproductions.net/articles/2006/01/20/caching-and-)  
memoization

Hope that helps.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![tele](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ba0ec/32.png) [@tele](https://www.ruby-forum.com/u/tele)\
**Post date:** [October 5, 2006, 3:38pm UTC](https://www.ruby-forum.com/t/weakrefs-and-object-caching/71100/3 "2006-10-05T15:38:51Z")

</div>

really interesting!  
i’ve a look

thank you
