mirror of
https://github.com/neocities/neocities.git
synced 2025-08-04 16:51:36 +02:00
more copy fixes
This commit is contained in:
parent
46e05ccb54
commit
3b0dd09b97
6 changed files with 50 additions and 12 deletions
25
models/simple_cache.rb
Normal file
25
models/simple_cache.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue