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
103 104 105 106 |
# File 'lib/rails/cache/tags/store.rb', line 103 def delete_tag(*names) = Tag.build(names) .each { |tag| tag_set.expire(tag) } end |
#exist_with_tags?(name, options = nil) ⇒ Boolean
66 67 68 |
# File 'lib/rails/cache/tags/store.rb', line 66 def (name, = nil) (name, ) && !read(name, ).nil? end |
#fetch_with_tags(name, options = nil) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rails/cache/tags/store.rb', line 79 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
70 71 72 73 74 75 76 77 |
# File 'lib/rails/cache/tags/store.rb', line 70 def (*names) result = (*names) 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
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rails/cache/tags/store.rb', line 39 def (name, = nil) result = (name, ) return if result.nil? entry = tag_set.check(result) if entry entry else delete(name, ) nil end end |
#tag_set ⇒ Object
35 36 37 |
# File 'lib/rails/cache/tags/store.rb', line 35 def tag_set @tag_set ||= Set.new(self) end |
#write_with_tags(name, value, options = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rails/cache/tags/store.rb', line 53 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 |