Skip to content

Instantly share code, notes, and snippets.

@antonbaron
antonbaron / cache_tag_invalidation.rb
Created September 23, 2012 01:50
Simulates Rails cache tags invalidation. Allows using cache like Rails.cache.fetch [key, tag] do .... end and Rails.cache.clear_tag tag
# config/initializers/cache_tag_invalidation.rb
module CacheTagInvalidation
puts <<-WARNING
Adding cache tag invalidation.
NOTICE that this will work only with MemoryStore on single process or with memcached store
WARNING
def write *args
if args.first.is_a?(Array) && args.first.size == 2 # Simulate tags only whan cache key is an array of 2 elements
key, tag = args.first
taglist_key = ["CacheTagList", tag]