Class: Store::Cache
- Inherits:
-
Object
- Object
- Store::Cache
- Defined in:
- lib/store/cache.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
Instance Method Summary collapse
- #all(table) ⇒ Object
- #close ⇒ Object
- #collate(*args) ⇒ Object
- #count(table) ⇒ Object
- #create(*args) ⇒ Object
- #create_equal_filter(*args) ⇒ Object
- #create_gt_filter(*args) ⇒ Object
- #create_gte_filter(*args) ⇒ Object
- #create_lt_filter(*args) ⇒ Object
- #each(table) ⇒ Object
- #find(*args) ⇒ Object
-
#initialize(backend_store, args = {}) ⇒ Cache
constructor
A new instance of Cache.
- #reset(*args) ⇒ Object
- #timestamper ⇒ Object
- #timestamper=(ts) ⇒ Object
- #update(*args) ⇒ Object
Constructor Details
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
6 7 8 |
# File 'lib/store/cache.rb', line 6 def backend @backend end |
Instance Method Details
#all(table) ⇒ Object
40 41 42 |
# File 'lib/store/cache.rb', line 40 def all table each(table).map{|i|i} end |
#close ⇒ Object
25 26 27 28 |
# File 'lib/store/cache.rb', line 25 def close @cache.invalidate backend.close end |
#collate(*args) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/store/cache.rb', line 74 def collate *args key = Marshal.dump(args) if data=@cache.load(key) data else data = backend.collate(*args) @cache.save(key,data) data end end |
#count(table) ⇒ Object
44 45 46 |
# File 'lib/store/cache.rb', line 44 def count table backend.count(table) end |
#create(*args) ⇒ Object
30 31 32 33 |
# File 'lib/store/cache.rb', line 30 def create *args @cache.invalidate backend.create *args end |
#create_equal_filter(*args) ⇒ Object
85 86 87 |
# File 'lib/store/cache.rb', line 85 def create_equal_filter *args backend.create_equal_filter(*args) end |
#create_gt_filter(*args) ⇒ Object
91 92 93 |
# File 'lib/store/cache.rb', line 91 def create_gt_filter *args backend.create_gt_filter(*args) end |
#create_gte_filter(*args) ⇒ Object
94 95 96 |
# File 'lib/store/cache.rb', line 94 def create_gte_filter *args backend.create_gte_filter(*args) end |
#create_lt_filter(*args) ⇒ Object
88 89 90 |
# File 'lib/store/cache.rb', line 88 def create_lt_filter *args backend.create_lt_filter(*args) end |
#each(table) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/store/cache.rb', line 48 def each table if data=@cache.load(table) data else data = backend.all(table) @cache.save table, data data end end |
#find(*args) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/store/cache.rb', line 63 def find *args key = Marshal.dump(args) if data=@cache.load(key) data else data = backend.find(*args) @cache.save key, data data end end |
#reset(*args) ⇒ Object
58 59 60 61 |
# File 'lib/store/cache.rb', line 58 def reset *args @cache.invalidate backend.reset(*args) end |
#timestamper ⇒ Object
21 22 23 |
# File 'lib/store/cache.rb', line 21 def backend. end |
#timestamper=(ts) ⇒ Object
17 18 19 |
# File 'lib/store/cache.rb', line 17 def ts backend. = ts end |
#update(*args) ⇒ Object
35 36 37 38 |
# File 'lib/store/cache.rb', line 35 def update *args @cache.invalidate backend.update *args end |