Module: Sequel::Plugins::ActsAsCacheable::ClassMethods
- Defined in:
- lib/sequel_acts_as_cacheable.rb
Instance Attribute Summary collapse
-
#acts_as_cacheable_cache ⇒ Object
Returns the value of attribute acts_as_cacheable_cache.
-
#acts_as_cacheable_logger ⇒ Object
Returns the value of attribute acts_as_cacheable_logger.
-
#acts_as_cacheable_time_to_live ⇒ Object
Returns the value of attribute acts_as_cacheable_time_to_live.
Instance Method Summary collapse
- #[](*args) ⇒ Object
-
#inherited(subclass) ⇒ Object
Copy the necessary class instance variables to the subclass.
- #model_cache_key(model_id) ⇒ Object
Instance Attribute Details
#acts_as_cacheable_cache ⇒ Object
Returns the value of attribute acts_as_cacheable_cache.
13 14 15 |
# File 'lib/sequel_acts_as_cacheable.rb', line 13 def acts_as_cacheable_cache @acts_as_cacheable_cache end |
#acts_as_cacheable_logger ⇒ Object
Returns the value of attribute acts_as_cacheable_logger.
15 16 17 |
# File 'lib/sequel_acts_as_cacheable.rb', line 15 def acts_as_cacheable_logger @acts_as_cacheable_logger end |
#acts_as_cacheable_time_to_live ⇒ Object
Returns the value of attribute acts_as_cacheable_time_to_live.
14 15 16 |
# File 'lib/sequel_acts_as_cacheable.rb', line 14 def acts_as_cacheable_time_to_live @acts_as_cacheable_time_to_live end |
Instance Method Details
#[](*args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sequel_acts_as_cacheable.rb', line 31 def [](*args) is_primary_key_lookup = if 1 == args.size if Fixnum == args.first.class true else if String == args.first.class begin Integer(args.first) true rescue false end else false end end else false end if is_primary_key_lookup key = model_cache_key args.first begin cache_value = @acts_as_cacheable_cache.get key rescue Exception => e if acts_as_cacheable_logger acts_as_cacheable_logger.error "CACHE.get failed in primary key lookup with args #{args.inspect} and model #{name} so using mysql lookup instead, exception was #{e.inspect}" end cache_value = super *args end if !cache_value cache_value = super *args cache_value.cache! if cache_value end if cache_value.kind_of? self cache_value else nil end else super *args end end |
#inherited(subclass) ⇒ Object
Copy the necessary class instance variables to the subclass.
18 19 20 21 22 23 |
# File 'lib/sequel_acts_as_cacheable.rb', line 18 def inherited(subclass) super subclass.acts_as_cacheable_cache = acts_as_cacheable_cache subclass.acts_as_cacheable_time_to_live = acts_as_cacheable_time_to_live subclass.acts_as_cacheable_logger = acts_as_cacheable_logger end |
#model_cache_key(model_id) ⇒ Object
25 26 27 28 29 |
# File 'lib/sequel_acts_as_cacheable.rb', line 25 def model_cache_key model_id base_model_klass = self base_model_klass = base_model_klass.superclass while Sequel::Model != base_model_klass.superclass "#{base_model_klass.name}~#{model_id}" end |