📜 ⬆️ ⬇️

Tag Emulation in MemCacheStore

Hello habr.
Actually I will start without preludes, I have not been nicely trained to write, so excuse me right away .

For a long time I was looking for a really working, written on ruby ​​for rails, library that would allow to tag tags of cache

So, it was too painful for me to have Koterov’s implementation. And I decided to actually copy the most important piece from php to ruby ​​today at the end of Friday. I do not claim the laurels, it may just be useful to someone, because Google did not tell me any ready implementations.

Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  1. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  2. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  3. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  4. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  5. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  6. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  7. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  8. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  9. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  10. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  11. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  12. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  13. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  14. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  15. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  16. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  17. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  18. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  19. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  20. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  21. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  22. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  23. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  24. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  25. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  26. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  27. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  28. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  29. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  30. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  31. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  32. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  33. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  34. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  35. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  36. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  37. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  38. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  39. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  40. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  41. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  42. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  43. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  44. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  45. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  46. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  47. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  48. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  49. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  50. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  51. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  52. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  53. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  54. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  55. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  56. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  57. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  58. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end
  59. Copy Source | Copy HTML ActiveSupport::Cache::MemCacheStore.class_eval do def read_with_tags key, options = nil # Data is saved in form of: [tagsWithVersionArray, anyData]. serialized = read_without_tags(key, options) return nil unless serialized combined = Marshal :: load (serialized) return nil unless combined.is_a?( Array ) # Test if all tags has the same version as when the slot was created # (ie still not removed and then recreated). if combined. first .is_a?( Hash ) && !combined. first .empty? all_tag_values = read_multi(combined. first .keys) combined. first .each_pair do |tag, saved_tag_version| actual_tag_version = all_tag_values[tag] return nil if actual_tag_version != saved_tag_version end end combined.last end def write_with_tags key, value, options = nil tags = options.is_a?( Hash ) ? options. delete (:tags) : [] tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) # Save/update tags as usual infinite keys with value of tag version. # If the tag already exists, do not rewrite it. tags_with_version = {} tags.each do |tag| tag_key = tag .to_s tag_version = read_without_tags tag_key if tag_version. nil ? tag_version = generate_new_tag_version write_without_tags tag_key, tag_version end tags_with_version[tag_key] = tag_version end if tags.is_a?( Array ) && !tags.empty? write_without_tags key, Marshal ::dump([tags_with_version, value]), options end def delete_by_tags tags, options = nil return nil if tags.blank? tags = tags. to_a .map{|item| "#{item[0]}:#{item[1]}" } if tags.is_a?( Hash ) tags.each{|tag| delete (tag, options)} end def generate_new_tag_version @@tag_version_counter ||= 0 @@tag_version_counter += 1 Digest::SHA1.hexdigest( "#{Time.now.to_f}_#{rand}_#{@@tag_version_counter}" ) end alias_method_chain :read, :tags alias_method_chain :write, :tags end module ActionController module Caching module Fragments def expire_fragments_by_tags *args return unless cache_configured? tags = args.extract_options! cache_store. delete_by_tags tags end end end end

')
And put it all in /config/initializers/mem_cache_tags_store.rb
For the code, please do not kick, because I’m writing only half a year, before php is about five years old, which I can’t see now without tears :)

Well, actually it works like this:
Rails.cache.write 'key', 'value', {:tags => ['company_1', 'user_2']}
Rails.cache.read 'key'
=> "value"
Rails.cache.delete_by_tags ['user_2']
Rails.cache.read 'key'
=> nil

Source: https://habr.com/ru/post/102253/


All Articles