# Memcache-client/cached\_model help

**URL:** <https://www.ruby-forum.com/t/memcache-client-cached-model-help/66074>\
**Category:** Rails\
**Created:** [February 12, 2006, 7:35am UTC](https://www.ruby-forum.com/t/memcache-client-cached-model-help/66074 "2006-02-12T07:35:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![magic6435](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@magic6435](https://www.ruby-forum.com/u/magic6435)\
**Post date:** [February 12, 2006, 7:35am UTC](https://www.ruby-forum.com/t/memcache-client-cached-model-help/66074/1 "2006-02-12T07:35:32Z")

</div>

Hi -

Just downloaded and installed the memcache-client and cached\_model  
gems and am trying to test it out on a development setup. I added  
this to my environment/development.rb

CACHE = MemCache.new :c\_threshold =\> 10\_000,  
:compression =\> true,  
:debug =\> true,  
:namespace =\> ‘eztrip’,  
:readonly =\> false,  
:urlencode =\> false  
CACHE.servers = ‘127.0.0.1:11211’

session\_options = {  
:database\_manager =\> CGI::Session::MemCacheStore,  
:cache =\> CACHE,  
:session\_domain =\> ‘[www.eztrip.com](http://www.eztrip.com)’  
}

ActionController::CgiRequest::DEFAULT\_SESSION\_OPTIONS.update  
session\_options

I also changed a few models to extend CachedModel but am having  
trouble getting it to work. I can manually put things in the cache  
and take them out of memcached but when I use cached\_model on my home  
page I get this in my console:

MemCache Set (0.091822) active\_record:EntityType:1  
MemCache Set (0.190003) active\_record:EntityType:2  
MemCache Set (0.199389) active\_record:EntityType:3  
  
MemCache Set (0.199342) active\_record:EntityType:17  
MemCache Set (0.228083) active\_record:EntityType:18  
MemCache Set (0.248523) active\_record:EntityType:19

which seems promising but when I hit refresh the same output is  
generated. I’m assuming that when I hit refresh the Set’s should all  
trun to Get’s?

Thanks for any pointers.  
Mike

---

<div class="post-metadata">

**Author:** ![magic6435](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@magic6435](https://www.ruby-forum.com/u/magic6435)\
**Post date:** [February 13, 2006, 8:44pm UTC](https://www.ruby-forum.com/t/memcache-client-cached-model-help/66074/2 "2006-02-13T20:44:59Z")

</div>

On Feb 11, 2006, at 10:35 PM, Michael E. wrote:

> MemCache Set (0.228083) active\_record:EntityType:18  
> MemCache Set (0.248523) active\_record:EntityType:19
> 
> which seems promising but when I hit refresh the same output is  
> generated. I’m assuming that when I hit refresh the Set’s should all  
> trun to Get’s?

If you perform a query that fetches multiple records a set will be  
issued for the each of the retrieved records. You may not see gets  
due to the local cache.

Note, you should call cache\_reset via a before\_filter otherwise you  
may have uncontrolled process growth.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://segment7.net](http://segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![magic6435](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@magic6435](https://www.ruby-forum.com/u/magic6435)\
**Post date:** [February 14, 2006, 1:50am UTC](https://www.ruby-forum.com/t/memcache-client-cached-model-help/66074/3 "2006-02-14T01:50:55Z")

</div>

Thanks for the reply. I looked at the code and I see why it’s making  
all  
the Set commands but the query that does this is a simple  
SELECT \* FROM entity\_types;

so shouldln’t it put it into memcached? In this case this table is  
pretty  
much read only so I wouldn’t want it to go into a local cache.

I think I just don’t understand what CachedModel is trying to do.

Thanks again  
Mike

---

<div class="post-metadata">

**Author:** ![magic6435](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@magic6435](https://www.ruby-forum.com/u/magic6435)\
**Post date:** [February 17, 2006, 7:58pm UTC](https://www.ruby-forum.com/t/memcache-client-cached-model-help/66074/4 "2006-02-17T19:58:55Z")

</div>

On Feb 13, 2006, at 4:50 PM, Michael E. wrote:

> Thanks for the reply. I looked at the code and I see why it’s  
> making all the Set commands but the query that does this is a simple  
> SELECT \* FROM entity\_types;
> 
> so shouldln’t it put it into memcached? In this case this table  
> is pretty much read only so I wouldn’t want it to go into a local  
> cache.

Since the table is “pretty much read only” how should cached\_model  
know when it is stale?

> I think I just don’t understand what CachedModel is trying to do.

Say a DB lookup for a single row takes 10ms. Say memcached can  
return the same row in 1ms. That’s a load your database doesn’t need  
to handle anymore.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://segment7.net](http://segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
