Module: Rails::Cache::Tags::Store
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rails/cache/tags/store.rb
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
-
#delete_tag(*names) ⇒ Object
(also: #delete_by_tag, #delete_by_tags, #expire_tag)
Increment the version of tags, so all entries referring to the tags become invalid.
- #exist_with_tags?(name, options = nil) ⇒ Boolean
- #fetch_with_tags(name, options = nil) ⇒ Object
- #read_multi_with_tags(*names) ⇒ Object
- #read_with_tags(name, options = nil) ⇒ Object
- #tag_set ⇒ Object
- #write_with_tags(name, value, options = nil) ⇒ Object
Instance Method Details
#delete_tag(*names) ⇒ Object Also known as: delete_by_tag, , expire_tag
Increment the version of tags, so all entries referring to the tags become invalid
92 93 94 95 |
# File 'lib/rails/cache/tags/store.rb', line 92 def delete_tag(*names) = Tag.build(names) .each { |tag| tag_set.expire(tag) } end |
#exist_with_tags?(name, options = nil) ⇒ Boolean
56 57 58 |
# File 'lib/rails/cache/tags/store.rb', line 56 def (name, = nil) (name, ) && !read(name).nil? end |
#fetch_with_tags(name, options = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rails/cache/tags/store.rb', line 68 def (name, = nil) return read(name, ) unless block_given? yielded = false result = (name, ) do yielded = true yield end if yielded result else # only :read occured # read occured, and result is fresh if (entry = tag_set.check(result)) entry else # result is stale delete(name) fetch(name, ) { yield } end end end |
#read_multi_with_tags(*names) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/rails/cache/tags/store.rb', line 60 def (*names) result = (*names) names.each_with_object(Hash.new) do |name, hash| hash[name.to_s] = tag_set.check(result[name.to_s]) end end |
#read_with_tags(name, options = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails/cache/tags/store.rb', line 30 def (name, = nil) result = (name, ) entry = tag_set.check(result) if entry entry else delete(name) nil end end |
#tag_set ⇒ Object
26 27 28 |
# File 'lib/rails/cache/tags/store.rb', line 26 def tag_set @tag_set ||= Set.new(self) end |
#write_with_tags(name, value, options = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rails/cache/tags/store.rb', line 43 def (name, value, = nil) if && [:tags].present? = Tag.build([:tags]) = .each_with_object(Hash.new) do |tag, hash| hash[tag.name] = tag_set.current(tag) end value = Entry.new(value, ) end (name, value, ) end |