These options will be passed through to url_for. In particular,
you can use this to differentiate between two or more cached fragments on the
same page:
<% cache(:id => 'one') do %>
This is cached as example.com/some/action/one.
<% end %>
<% cache(:id => 'two') do %>
This is cached as example.com/some/action/two.
<% end %>
The url_for function is only used here to provide a unique name for the cached fragment;
it does not need to map to a real-world route. But sticking to these conventions
(the real action name plus an optional action suffix) will avoid collisions with
names of unrelated fragments.
Fragment expiration. The expire_fragment method removes a fragment from the
cache. It takes either a string or a hash argument, in the same format as the write_
fragment and cache methods. If passed a hash, it will run it through url_for and
delete the appropriate items from the cache.
Alternatively, expire_fragment can take a regular expression as an argument, and it
will delete all pages with keys matching that regexp. This is not recommended. That
syntax is not supported with memcached (which cannot iterate over its keys), and for
all other fragment cache stores, Rails must iterate over every key and check it against
the regular expression. This can slow things down tremendously.
Cache sweepers
As discussed before, cache sweepers are model observers that expire cached pages,
actions, and fragments when their model objects change.
Pages:
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282