MemCacheStoreのタグエミュレーション

こんにちは、ハブラ。

実際、私は序曲なしで始めます。 私は書くための美しく訓練されていないので、すみません



長い間、私はレール用のルビーで書かれた本当に機能するライブラリを探していました。



アヒル、 コテロフの実装が好きになって本当に痛かった 。 そして、私は実際に金曜日の終わりに今日最も重要な部分をPHPからルビーに書き直すことにしました。 私は月桂樹のふりをしません。誰かに役立つかもしれません。 Googleは既製の実装について通知しませんでした。



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







そして、すべてを/config/initializers/mem_cache_tags_store.rbに入れます

コードを蹴らないでください。なぜなら ルーブルで書いているのはたった6か月で、それ以前は5年間phpで書いていましたが、涙なしでは見られません:)



まあ、実際には何とかこのように動作します:

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








All Articles