How to expire cache in AR backend?

Hey,

how to expire cache in AR backend i.e. after updating a translation? I
think there’s a problem with cache_key method - it simply takes the
arguments passed to #translate and generates cache key based on them.
The problem is i.e. with count - it generates different cache keys for
these translations:

I18n.t(“key.with.count”, :count => 2)
I18n.t(“key.with.count”, :count => 3)
I18n.t(“key.with.count”, :count => 4)

because it passes {:count => x} to the cache_key method instead
of :other. This also causes a problem when I’m trying to expire cache,
because I can’t generate cache_key inside Translation model, because I
don’t have :count => x option.

How do you guys expire cache in AR backend? Or maybe it would be
possible to modify cache_key method to figure out the pluralization
first (i.e. :one, :other) and use this to build the cache key?

BTW. Isn’t Cache#cache_key going to generate different keys for normal
interpolation as well?

Regards,
Szymon

I’ve created ExpirableCache module for i18n:

that caches uninterpolated translations. I haven’t written any tests
for it yet, but if any of the i18n guys could take a look at it and
check if it makes any sense it would be great.

One of the problems is that currently if the translation in the
database has nil value, it can’t be stored in the cache:

cache_store.write(“key”, nil)
cache_store.exist?(“key”) => false

thus it always hits the db if the translation is missing. Maybe
storing false instead of nil could help here…

Cheers,
Szymon