Forum: Ruby on Rails memcache-client/cached_model help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F85e4d039cb54389389010fc095b6b6a?d=identicon&s=25 Michael Engelhart (Guest)
on 2006-02-12 07:35
(Received via mailing list)
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
<snip>
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
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-02-13 20:44
(Received via mailing list)
On Feb 11, 2006, at 10:35 PM, Michael Engelhart 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 Hodel - drbrain@segment7.net - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com
F85e4d039cb54389389010fc095b6b6a?d=identicon&s=25 Michael Engelhart (Guest)
on 2006-02-14 01:50
(Received via mailing list)
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
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-02-17 19:58
(Received via mailing list)
On Feb 13, 2006, at 4:50 PM, Michael Engelhart 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 Hodel - drbrain@segment7.net - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com
This topic is locked and can not be replied to.