module TDiary::Cache
Public Instance Methods
clear_cache(target = :all)
click to toggle source
# File lib/tdiary/cache/redis.rb, line 19 def clear_cache(target = :all) if target == :all delete_data(:all) else ym = target.to_s.scan(/\d{4}\d{2}/)[0] ['latest.rb', 'i.latest.rb', "#{ym}.rb", "i.#{ym}.rb"].each do |key| delete_data(key) end end end
restore_cache(prefix)
click to toggle source
# File lib/tdiary/cache/redis.rb, line 7 def restore_cache(prefix) if key = cache_key(prefix) restore_data(key) end end
store_cache(cache, prefix)
click to toggle source
# File lib/tdiary/cache/redis.rb, line 13 def store_cache(cache, prefix) if key = cache_key(prefix) store_data(cache, key) end end
Private Instance Methods
cache_key(prefix)
click to toggle source
# File lib/tdiary/cache/redis.rb, line 70 def cache_key(prefix) if @tdiary.is_a?(TDiaryMonth) "#{prefix}#{@tdiary.rhtml.sub( /month/, @tdiary.date.strftime( '%Y%m' ) ).sub( /\.rhtml$/, '.rb' )}" elsif @tdiary.is_a?(TDiaryLatest) if @tdiary.cgi.params['date'][0] nil else "#{prefix}#{@tdiary.rhtml.sub( /\.rhtml$/, '.rb' )}" end else nil end end
clear_parser_cache(date)
click to toggle source
# File lib/tdiary/cache/redis.rb, line 66 def clear_parser_cache(date) redis.flushdb end
delete_data(key)
click to toggle source
# File lib/tdiary/cache/redis.rb, line 45 def delete_data(key) if key == :all redis.flushdb else redis.del(key) end end
redis()
click to toggle source
# File lib/tdiary/cache/redis.rb, line 84 def redis @_client ||= if @tdiary.conf.user_name Redis::Namespace.new(@tdiary.conf.user_name.to_sym, redis: Redis.new) else Redis.new end end
restore_data(key)
click to toggle source
# File lib/tdiary/cache/redis.rb, line 32 def restore_data(key) obj = redis.get(key) if obj.nil? nil else YAML.load(obj) end end
restore_parser_cache(date, key = nil)
click to toggle source
# File lib/tdiary/cache/redis.rb, line 53 def restore_parser_cache(date, key = nil) obj = redis.get(date.strftime("%Y%m.parser")) if obj.nil? nil else YAML.load(obj) end end
store_data(data, key)
click to toggle source
# File lib/tdiary/cache/redis.rb, line 41 def store_data(data, key) redis.set(key, YAML.dump(data)) end
store_parser_cache(date, obj, key = nil)
click to toggle source
# File lib/tdiary/cache/redis.rb, line 62 def store_parser_cache(date, obj, key = nil) redis.set(date.strftime("%Y%m.parser"), YAML.dump(obj)) end