Class: Slugable::CacheLayer
- Inherits:
-
Object
- Object
- Slugable::CacheLayer
- Defined in:
- lib/slugable/cache_layer.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
-
#initialize(storage, model) ⇒ CacheLayer
constructor
A new instance of CacheLayer.
- #read_slug(slug_column, id) ⇒ Object
- #update(slug_column, id, value) ⇒ Object
Constructor Details
#initialize(storage, model) ⇒ CacheLayer
Returns a new instance of CacheLayer.
5 6 7 8 |
# File 'lib/slugable/cache_layer.rb', line 5 def initialize(storage, model) @storage = storage @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/slugable/cache_layer.rb', line 3 def model @model end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
3 4 5 |
# File 'lib/slugable/cache_layer.rb', line 3 def storage @storage end |
Instance Method Details
#read_slug(slug_column, id) ⇒ Object
10 11 12 |
# File 'lib/slugable/cache_layer.rb', line 10 def read_slug(slug_column, id) storage.fetch(cache_key(slug_column, id)) { model.find(id).public_send(slug_column) } end |
#update(slug_column, id, value) ⇒ Object
14 15 16 |
# File 'lib/slugable/cache_layer.rb', line 14 def update(slug_column, id, value) storage.write(cache_key(slug_column, id), value) end |