|
|
@ -3,12 +3,17 @@ local Cache = {} |
|
|
|
Cache.__index = Cache |
|
|
|
Cache.__index = Cache |
|
|
|
|
|
|
|
|
|
|
|
-- Constructor |
|
|
|
-- Constructor |
|
|
|
|
|
|
|
---@return Cache |
|
|
|
function Cache:New() |
|
|
|
function Cache:New() |
|
|
|
local self = setmetatable({}, Cache) |
|
|
|
local self = setmetatable({}, Cache) |
|
|
|
self.cache = {} |
|
|
|
self.cache = {} |
|
|
|
return self |
|
|
|
return self |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@param key any |
|
|
|
|
|
|
|
---@param value any |
|
|
|
|
|
|
|
---@param duration number |
|
|
|
|
|
|
|
---@return nil |
|
|
|
function Cache:Set(key, value, duration) |
|
|
|
function Cache:Set(key, value, duration) |
|
|
|
self.cache = self.cache or {} |
|
|
|
self.cache = self.cache or {} |
|
|
|
self.cache[key] = { |
|
|
|
self.cache[key] = { |
|
|
@ -18,6 +23,8 @@ function Cache:Set(key, value, duration) |
|
|
|
} |
|
|
|
} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@param key any |
|
|
|
|
|
|
|
---@return any |
|
|
|
function Cache:Get(key) |
|
|
|
function Cache:Get(key) |
|
|
|
self.cache = self.cache or {} |
|
|
|
self.cache = self.cache or {} |
|
|
|
local cache = self.cache[key] |
|
|
|
local cache = self.cache[key] |
|
|
@ -31,6 +38,8 @@ function Cache:Get(key) |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@param key any |
|
|
|
|
|
|
|
---@return boolean |
|
|
|
function Cache:IsCached(key) |
|
|
|
function Cache:IsCached(key) |
|
|
|
self.cache = self.cache or {} |
|
|
|
self.cache = self.cache or {} |
|
|
|
local cache = self.cache[key] |
|
|
|
local cache = self.cache[key] |
|
|
|