Module: RedisCacheable::ClassMethods
- Defined in:
- lib/redis_cacheable.rb
Instance Method Summary collapse
-
#__redis_cache_attrs__ ⇒ Object
for internal use.
-
#__redis_cache_key__ ⇒ Object
for internal use.
- #del_from_redis(key) ⇒ Object
- #find_from_redis(key) ⇒ String || Number || Array || Hash
- #inherited(subclass) ⇒ Object
- #redis_attrs(*attributes) ⇒ Object
- #redis_key(key) ⇒ Object
Instance Method Details
#__redis_cache_attrs__ ⇒ Object
for internal use
84 85 86 |
# File 'lib/redis_cacheable.rb', line 84 def __redis_cache_attrs__ @__redis_cache_attrs__ || [] end |
#__redis_cache_key__ ⇒ Object
for internal use
78 79 80 |
# File 'lib/redis_cacheable.rb', line 78 def __redis_cache_key__ @__redis_cache_key__ || :id end |
#del_from_redis(key) ⇒ Object
70 71 72 73 74 |
# File 'lib/redis_cacheable.rb', line 70 def del_from_redis(key) redis do |conn| conn.del(key) end end |
#find_from_redis(key) ⇒ String || Number || Array || Hash
61 62 63 64 65 66 67 68 |
# File 'lib/redis_cacheable.rb', line 61 def find_from_redis(key) redis do |conn| json = conn.get(key) return nil unless json MultiJson.load(json) end end |
#inherited(subclass) ⇒ Object
32 33 34 35 |
# File 'lib/redis_cacheable.rb', line 32 def inherited(subclass) subclass.instance_variable_set("@__redis_cache_key__", @__redis_cache_key__) subclass.instance_variable_set("@__redis_cache_attrs__", @__redis_cache_attrs__) end |
#redis_attrs(*attributes) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/redis_cacheable.rb', line 51 def redis_attrs(*attributes) if attributes.first.is_a?(Proc) @__redis_cache_attrs__ = attributes.first else @__redis_cache_attrs__ = attributes.flatten end end |
#redis_key(key) ⇒ Object
42 43 44 |
# File 'lib/redis_cacheable.rb', line 42 def redis_key(key) @__redis_cache_key__ = key end |