Class: Trebuchet::Backend::RedisCached
- Inherits:
-
Redis
- Object
- Redis
- Trebuchet::Backend::RedisCached
show all
- Defined in:
- lib/trebuchet/backend/redis_cached.rb
Instance Attribute Summary
Attributes inherited from Redis
#namespace
Instance Method Summary
collapse
Methods inherited from Redis
#get_all_history, #get_archived_feature_names, #get_feature_names, #get_history, #get_sentinel, #initialize, #remove_feature, #remove_strategy, #set_strategy, #store_history, #unpack_strategy, #update_sentinel
Instance Method Details
#append_strategy(feature_name, strategy, options = nil) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/trebuchet/backend/redis_cached.rb', line 19
def append_strategy(feature_name, strategy, options = nil)
clear_cached_strategies
super(feature_name, strategy, options)
end
|
#cache_cleared_at ⇒ Object
34
35
36
|
# File 'lib/trebuchet/backend/redis_cached.rb', line 34
def cache_cleared_at
@cache_cleared_at ||= Time.now
end
|
#cache_strategy(feature_name, strategy) ⇒ Object
26
27
28
|
# File 'lib/trebuchet/backend/redis_cached.rb', line 26
def cache_strategy(feature_name, strategy)
cached_strategies[feature_name] = strategy
end
|
#cached_strategies ⇒ Object
30
31
32
|
# File 'lib/trebuchet/backend/redis_cached.rb', line 30
def cached_strategies
@cached_strategies ||= Hash.new
end
|
#clear_cached_strategies ⇒ Object
38
39
40
41
|
# File 'lib/trebuchet/backend/redis_cached.rb', line 38
def clear_cached_strategies
@cache_cleared_at = Time.now
@cached_strategies = nil
end
|
#get_strategy(feature_name) ⇒ Object
cache strategies in memory until clear_cached_strategies is called
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/trebuchet/backend/redis_cached.rb', line 7
def get_strategy(feature_name)
if cached_strategies.has_key?(feature_name)
cached_strategies[feature_name]
else
cache_strategy feature_name, super(feature_name)
end
end
|
#refresh ⇒ Object
43
44
45
|
# File 'lib/trebuchet/backend/redis_cached.rb', line 43
def refresh
clear_cached_strategies if Time.now > cache_cleared_at + 60.seconds
end
|