mirror of
https://github.com/koreader/koreader
synced 2024-11-16 06:12:56 +00:00
2635593890
* Allow doing away with CacheItem Now that we have working FFI finalizers on BBs, it's mostly useless overhead. We only keep it for DocCache, because it's slightly larger, and memory pressure might put us in a do or die situation where waiting for the GC might mean an OOM kill. * Expose's LRU slot-only mode And use it for CatalogCache, which doesn't care about storage space * Make GlyphCache slots only (storage space is insignificant here, it was always going to be evicted by running out of slots). * More informative warning when we chop the cache in half
26 lines
814 B
Lua
26 lines
814 B
Lua
--[[
|
|
Inheritable abstraction for cache items
|
|
--]]
|
|
|
|
local CacheItem = {
|
|
size = 128, -- some reasonable default for a small table.
|
|
}
|
|
--- 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.
|
|
|
|
function CacheItem:new(o)
|
|
o = o or {}
|
|
setmetatable(o, self)
|
|
self.__index = self
|
|
return o
|
|
end
|
|
|
|
-- Called on eviction.
|
|
-- 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
|
|
function CacheItem:onFree()
|
|
end
|
|
|
|
return CacheItem
|