2013-10-18 20:38:07 +00:00
|
|
|
--[[
|
|
|
|
Inheritable abstraction for cache items
|
|
|
|
--]]
|
|
|
|
|
|
|
|
local CacheItem = {
|
2021-05-03 03:20:14 +00:00
|
|
|
size = 128, -- some reasonable default for a small table.
|
2013-10-18 20:38:07 +00:00
|
|
|
}
|
2021-05-03 03:20:14 +00:00
|
|
|
--- NOTE: As far as size estimations go, the assumption is that a key, value pair should roughly take two words,
|
|
|
|
--- and the most common items we cache are Geom-like tables (i.e., 4 key-value pairs).
|
|
|
|
--- That's generally a low estimation, especially for larger tables, where memory allocation trickery may be happening.
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
function CacheItem:new(o)
|
2014-03-13 13:52:43 +00:00
|
|
|
o = o or {}
|
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
return o
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
2021-05-04 21:13:24 +00:00
|
|
|
-- Called on eviction.
|
2021-05-07 01:59:27 +00:00
|
|
|
-- We generally use it to free C/FFI resources *immediately* (as opposed to relying on our Userdata/FFI finalizers to do it "later" on GC).
|
|
|
|
-- c.f., TileCacheItem
|
2013-10-18 20:38:07 +00:00
|
|
|
function CacheItem:onFree()
|
|
|
|
end
|
|
|
|
|
|
|
|
return CacheItem
|