Class: Experimental::Source::Cache
- Defined in:
- lib/experimental/source/cache.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #available ⇒ Object
-
#initialize(source, options = {}) ⇒ Cache
constructor
A cache source provides in memory caching around another source.
Constructor Details
#initialize(source, options = {}) ⇒ Cache
A cache source provides in memory caching around another source.
If a :ttl
option is passed, experiments will only be cached for that many seconds, otherwise it is cached forever.
8 9 10 11 12 13 |
# File 'lib/experimental/source/cache.rb', line 8 def initialize(source, = {}) @source = source @ttl = [:ttl] @last_update = nil @cache = {} end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
15 16 17 |
# File 'lib/experimental/source/cache.rb', line 15 def source @source end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
15 16 17 |
# File 'lib/experimental/source/cache.rb', line 15 def ttl @ttl end |
Instance Method Details
#[](name) ⇒ Object
17 18 19 20 |
# File 'lib/experimental/source/cache.rb', line 17 def [](name) refresh if dirty? cache[name.to_s] end |
#available ⇒ Object
22 23 24 25 |
# File 'lib/experimental/source/cache.rb', line 22 def available refresh if dirty? cache.values end |