Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cache = {}
- function cache:new() -- creates cache class object
- local private = { data = {} }
- local obj = {}
- function obj:put(key, value) -- cache value with specified name
- private.data[key] = value
- end
- function obj:get(key) -- get cached value by name or nil
- return private.data[key] or nil
- end
- function obj:remove(key) -- remove value from cache
- private.data[key] = nil
- end
- function obj:clear() -- clear cache
- private.data = {}
- end
- function obj:is_present(key) -- true if value cached, false otherwise
- if private.data[key] then
- return true
- else
- return false
- end
- end
- setmetatable(obj, self)
- self.__index = self
- return obj
- end
- return cache
Add Comment
Please, Sign In to add comment