Because of its simplicity, it is scalable and fast. It is designed never to
block, so there is no risk of deadlock. There are four simple operations on the cache,
each completing in constant time.
You can actually use memcached in several different places in Rails. It is available as
a session store or a fragment cache store out of the box, assuming the rubymemcache
gem is installed. It can also be used to store complete models??”but
remember that this will only be effective for applications where reads vastly outnumber
writes. There are two libraries that cover model caching: cached_model and
acts_as_cached.
The cached_model library (http://dev.robotcoop.com/Libraries/cached_model/index.
html) provides an abstract subclass of ActiveRecord::Base, CachedModel. It attempts
to be as transparent as possible, just caching the simple queries against single objects
and not trying to do anything fancy. It does have the disadvantage that all cached
models must inherit from CachedModel. Use of cached_model is dead simple:
class Client < CachedModel
end
On the other hand, the acts_as_cached plugin (http://errtheblog.com/post/27) gives
you more specificity over what is cached. It feels more like programming against
memcached??™s API, but there is more power and less verbosity. It has support for relationships
between objects, and it can even version each key to invalidate old keys
during a schema change.
Pages:
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188