more copy fixes

This commit is contained in:
Kyle Drake 2014-04-23 15:07:00 -07:00
parent 46e05ccb54
commit 3b0dd09b97
6 changed files with 50 additions and 12 deletions

25
models/simple_cache.rb Normal file
View file

@ -0,0 +1,25 @@
require 'thread'
require 'time'
module SimpleCache
@cache = {}
@semaphore = Mutex.new
class << self
def store(name, value, timeout=30)
@semaphore.synchronize {
@cache[name] = {value: value, expires_at: Time.now+timeout}
}
value
end
def get(name)
@cache[name][:value]
end
def expired?(name)
return false if @cache[name] && @cache[name][:expires_at] > Time.now
true
end
end
end