trabajo-afectivo/lib/cache.rb

24 lines
636 B
Ruby
Raw Normal View History

2012-07-29 15:27:01 +00:00
module Cache
def self.delete( key )
2012-10-23 19:19:07 +00:00
# puts 'Cache.delete' + key.to_s
2012-07-29 15:27:01 +00:00
Rails.cache.delete( key.to_s )
end
2012-07-29 15:34:30 +00:00
def self.write( key, data, params = {} )
if !params[:expires_in]
2012-07-29 18:55:51 +00:00
params[:expires_in] = 24.hours
2012-07-29 15:34:30 +00:00
end
2012-10-23 19:19:07 +00:00
# puts 'Cache.write: ' + key.to_s
2012-07-29 15:34:30 +00:00
Rails.cache.write( key.to_s, data, params)
2012-07-29 15:27:01 +00:00
end
def self.get( key )
2012-10-23 19:19:07 +00:00
# puts 'Cache.get: ' + key.to_s
2012-07-29 15:27:01 +00:00
Rails.cache.read( key.to_s )
end
2012-07-29 18:55:51 +00:00
def self.clear
2012-10-23 19:19:07 +00:00
# puts 'Cache.clear...'
# workaround, set test cache before clear whole cache, Rails.cache.clear complains about not existing cache dir
Cache.write('test',1 )
2012-07-29 18:55:51 +00:00
Rails.cache.clear
end
2012-07-29 15:27:01 +00:00
end