Class: KStor::StoreCache
- Inherits:
-
Object
- Object
- KStor::StoreCache
- Defined in:
- lib/kstor/store.rb
Overview
Simplistic cache for list of users and groups.
Instance Attribute Summary collapse
-
#groups ⇒ Object
Returns cached list of groups.
-
#users ⇒ Object
Returns cached list of users.
Class Method Summary collapse
-
.property(name) ⇒ Object
Declare a cached list of values.
Instance Method Summary collapse
-
#initialize ⇒ StoreCache
constructor
Create new cache.
Constructor Details
#initialize ⇒ StoreCache
Create new cache.
13 14 15 16 |
# File 'lib/kstor/store.rb', line 13 def initialize @cache = {} @cache.extend(Mutex_m) end |
Instance Attribute Details
#groups ⇒ Object
Returns cached list of groups
48 |
# File 'lib/kstor/store.rb', line 48 property :groups |
#users ⇒ Object
Returns cached list of users
46 |
# File 'lib/kstor/store.rb', line 46 property :users |
Class Method Details
.property(name) ⇒ Object
Declare a cached list of values.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kstor/store.rb', line 26 def property(name) define_method(name) do |&block| @cache.synchronize do return @cache[name] if @cache.key?(name) @cache[name] = block.call end end define_method("#{name}=".to_sym) do |list| @cache.synchronize { @cache[name] = list } end define_method("forget_#{name}") do @cache.synchronize { @cache.delete(name) } end end |