Memcache-client/cached_model help


#1

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
}

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


#2

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
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com


#3

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


#4

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
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com