Class: Cashier::Adapters::CacheStore

Inherits:
Object
  • Object
show all
Defined in:
lib/cashier/adapters/cache_store.rb

Class Method Summary collapse

Class Method Details

.clearObject



35
36
37
38
# File 'lib/cashier/adapters/cache_store.rb', line 35

def self.clear
  remove_tags(tags)
  Rails.cache.delete(Cashier::CACHE_KEY)
end

.delete_tag(tag) ⇒ Object



31
32
33
# File 'lib/cashier/adapters/cache_store.rb', line 31

def self.delete_tag(tag)
  Rails.cache.delete(tag)  
end

.get_fragments_for_tag(tag) ⇒ Object



27
28
29
# File 'lib/cashier/adapters/cache_store.rb', line 27

def self.get_fragments_for_tag(tag)
  Rails.cache.read(tag) || []
end

.keysObject



40
41
42
# File 'lib/cashier/adapters/cache_store.rb', line 40

def self.keys
  tags.inject([]) { |arry, tag| arry += Rails.cache.fetch(tag) }.compact
end

.remove_tags(tags) ⇒ Object



17
18
19
20
21
# File 'lib/cashier/adapters/cache_store.rb', line 17

def self.remove_tags(tags)
  cashier_tags = Rails.cache.fetch(Cashier::CACHE_KEY) || []
  cashier_tags = (cashier_tags - tags).uniq
  Rails.cache.write(Cashier::CACHE_KEY, cashier_tags)
end

.store_fragment_in_tag(fragment, tag) ⇒ Object



4
5
6
7
8
# File 'lib/cashier/adapters/cache_store.rb', line 4

def self.store_fragment_in_tag(fragment, tag)
  fragments = Rails.cache.fetch(tag) || []
  new_fragments = fragments + [fragment]
  Rails.cache.write(tag, new_fragments)
end

.store_tags(tags) ⇒ Object



10
11
12
13
14
15
# File 'lib/cashier/adapters/cache_store.rb', line 10

def self.store_tags(tags)
  cashier_tags = Rails.cache.fetch(Cashier::CACHE_KEY) || []
  cashier_tags = (cashier_tags + tags).uniq

  Rails.cache.write(Cashier::CACHE_KEY, cashier_tags)
end

.tagsObject



23
24
25
# File 'lib/cashier/adapters/cache_store.rb', line 23

def self.tags
  Rails.cache.read(Cashier::CACHE_KEY) || []
end