Class: ICFS::ConfigRedis
Overview
Implement Config with a Redis cache
Constant Summary
Constants inherited from Config
Instance Attribute Summary
Attributes inherited from Config
Instance Method Summary collapse
-
#initialize(redis, base, opts = {}) ⇒ ConfigRedis
constructor
New instance.
-
#load(unam) ⇒ Boolean
Load a user configuration.
-
#save ⇒ Object
Save a user configuration.
Methods inherited from Config
Constructor Details
#initialize(redis, base, opts = {}) ⇒ ConfigRedis
New instance
33 34 35 36 37 38 39 |
# File 'lib/icfs/config_redis.rb', line 33 def initialize(redis, base, opts={}) super(base.defaults) @redis = redis @base = base @pre = opts[:prefix] || '' @exp = opts[:expires] || 1*60*60 # 1 hour default end |
Instance Method Details
#load(unam) ⇒ Boolean
Load a user configuration
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/icfs/config_redis.rb', line 45 def load(unam) Items.validate(unam, 'User/Role/Group name', Items::FieldUsergrp) @unam = unam.dup key = _key(unam) # try cache json = @redis.get(key) if json @data = Items.parse(json, 'Config values', Config::ValConfig) return true end # get base object succ = @base.load(unam) @data = @base.data return succ end |