Class: Rails::Cache::Tags::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/cache/tags/set.rb

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ Set

Returns a new instance of Set.

Parameters:

  • store (ActiveSupport::Cache::Store)


11
12
13
14
# File 'lib/rails/cache/tags/set.rb', line 11

def initialize(store)
  @store = store
  @tags_cache = LocalCache.new
end

Instance Method Details

#check(entry) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/rails/cache/tags/set.rb', line 30

def check(entry)
  return entry unless entry.is_a?(Store::Entry)
  return entry.value if entry.tags.blank?

  tags = Tag.build(entry.tags.keys)

  saved_versions = entry.tags.values.map(&:to_i)

  saved_versions == current_versions(tags) ? entry.value : nil
end

#current(tag) ⇒ Object



16
17
18
19
20
21
# File 'lib/rails/cache/tags/set.rb', line 16

def current(tag)
  key = tag.to_key
  @tags_cache.fetch(key) do
    @store.fetch_without_tags(key) { 1 }.to_i
  end
end

#expire(tag) ⇒ Object



23
24
25
26
27
28
# File 'lib/rails/cache/tags/set.rb', line 23

def expire(tag)
  version = current(tag) + 1
  @store.write_without_tags(tag.to_key, version, :expires_in => nil)

  version
end