Module: Cashier
- Defined in:
- lib/cashier.rb,
lib/cashier/railtie.rb,
lib/cashier/version.rb,
lib/cashier/matchers.rb,
lib/cashier/adapters/cache_store.rb,
lib/cashier/adapters/redis_store.rb
Defined Under Namespace
Modules: Adapters, Matchers Classes: Railtie
Constant Summary collapse
- CACHE_KEY =
'cashier-tags'
- VERSION =
"0.4.1"
Class Method Summary collapse
-
.adapter ⇒ Object
Public: adapter which is used by cashier.
-
.adapter=(cache_adapter) ⇒ Object
Public: set the adapter the Cashier module will use to store the keys.
-
.clear ⇒ Object
Public: clears the tags.
-
.expire(*tags) ⇒ Object
Public: expire tags.
-
.keys ⇒ Object
Public: get all the keys names as an array.
-
.keys_for(tag) ⇒ Object
Public: get all the keys for a specific tag as an array.
-
.perform_caching? ⇒ Boolean
Public: whether the module will perform caching or not.
-
.store_fragment(fragment, *tags) ⇒ Object
Public: store a fragment with an array of tags for this fragment.
-
.tags ⇒ Object
Public: returns the array of tags stored in the tags store.
Class Method Details
.adapter ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/cashier.rb', line 131 def adapter if @@adapter == :cache_store Cashier::Adapters::CacheStore else Cashier::Adapters::RedisStore end end |
.adapter=(cache_adapter) ⇒ Object
147 148 149 |
# File 'lib/cashier.rb', line 147 def adapter=(cache_adapter) @@adapter = cache_adapter end |
.clear ⇒ Object
91 92 93 94 95 |
# File 'lib/cashier.rb', line 91 def clear ActiveSupport::Notifications.instrument("clear.cashier") do adapter.clear end end |
.expire(*tags) ⇒ Object
Public: expire tags. expiring the keys ‘assigned’ to the tags you expire and removes the tags from the tags list
tags - array of tags to expire.
Examples
Cashier.expire('tag1', 'tag2')
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cashier.rb', line 51 def expire(*) return unless perform_caching? ActiveSupport::Notifications.instrument("expire.cashier", :data => ) do # delete them from the cache .each do |tag| fragment_keys = adapter.get_fragments_for_tag(tag) fragment_keys.each do |fragment_key| Rails.cache.delete(fragment_key) end adapter.delete_tag(tag) end # now remove them from the list # of stored tags adapter.() end end |
.keys ⇒ Object
Public: get all the keys names as an array.
Examples
Cachier.keys
# => ['key1', 'key2', 'key3']
105 106 107 |
# File 'lib/cashier.rb', line 105 def keys adapter.keys end |
.keys_for(tag) ⇒ Object
Public: get all the keys for a specific tag as an array.
Examples
Cashier.('tag1')
# => ['key1', 'key2', 'key3']
117 118 119 |
# File 'lib/cashier.rb', line 117 def keys_for(tag) adapter.get_fragments_for_tag(tag) end |
.perform_caching? ⇒ Boolean
Public: whether the module will perform caching or not. this is being set in the application layer .perform_caching configuration
Examples
Cashier.perform_caching?
# => true
14 15 16 |
# File 'lib/cashier.rb', line 14 def perform_caching? ::ApplicationController.perform_caching end |
.store_fragment(fragment, *tags) ⇒ Object
Public: store a fragment with an array of tags for this fragment.
fragment - cached fragment. tags - array of tags you want to assign this fragments.
Examples
Cachier.store_fragment('foo', 'tag1', 'tag2', 'tag3')
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cashier.rb', line 27 def store_fragment(fragment, *) return unless perform_caching? = .flatten ActiveSupport::Notifications.instrument("store_fragment.cashier", :data => [fragment, ]) do .each do |tag| # store the fragment adapter.store_fragment_in_tag(fragment, tag) end # now store the tag for book keeping adapter.() end end |
.tags ⇒ Object
80 81 82 |
# File 'lib/cashier.rb', line 80 def adapter. end |