Class: AppCache::SystemParam

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/app_cache/system_param.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cache_updateObject



14
15
16
17
18
# File 'app/models/app_cache/system_param.rb', line 14

def self.cache_update
  params = AppCache::SystemParam.all.to_json
  AppCache.storage.del "system_params"
  AppCache.storage.set("system_params", params)
end

.get_cacheObject



20
21
22
23
# File 'app/models/app_cache/system_param.rb', line 20

def self.get_cache
  params = JSON.load AppCache.storage.get "system_params"
  params
end

.get_param_value(key) ⇒ Object



50
51
52
53
54
# File 'app/models/app_cache/system_param.rb', line 50

def self.get_param_value(key)
  params = self.get_params
  param_val = params[key] || ''
  param_val
end

.get_paramsObject



42
43
44
45
46
47
48
# File 'app/models/app_cache/system_param.rb', line 42

def self.get_params
  if AppCache.storage
    self.get_params_cache
  else
    self.get_params_db
  end
end

.get_params_cacheObject



25
26
27
28
29
30
31
32
# File 'app/models/app_cache/system_param.rb', line 25

def self.get_params_cache
  json = self.get_cache
  h = {}
  json.each do |sp|
    h.store(sp['param_code'], sp['param_value'])
  end
  return h
end

.get_params_dbObject



34
35
36
37
38
39
40
# File 'app/models/app_cache/system_param.rb', line 34

def self.get_params_db
  h = {}
  AppCache::SystemParam.all.each do |sp|
    h.store(sp.param_code, sp.param_value)
  end
  h
end

Instance Method Details

#auto_cache_updateObject



6
7
8
9
10
11
12
# File 'app/models/app_cache/system_param.rb', line 6

def auto_cache_update
  if AppCache.storage
    params = AppCache::SystemParam.all.to_json
    AppCache.storage.del "system_params"
    AppCache.storage.set("system_params", params)
  end
end