mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
* 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
27 lines
991 B
Lua
27 lines
991 B
Lua
--[[
|
|
"Global" LRU cache used by Document & friends.
|
|
--]]
|
|
|
|
local Cache = require("cache")
|
|
local CanvasContext = require("document/canvascontext")
|
|
local DataStorage = require("datastorage")
|
|
|
|
local function calcCacheMemSize()
|
|
local min = DGLOBAL_CACHE_SIZE_MINIMUM
|
|
local max = DGLOBAL_CACHE_SIZE_MAXIMUM
|
|
local calc = Cache:_calcFreeMem() * (DGLOBAL_CACHE_FREE_PROPORTION or 0)
|
|
return math.min(max, math.max(min, calc))
|
|
end
|
|
|
|
local DocCache = Cache:new{
|
|
size = calcCacheMemSize(),
|
|
-- Average item size is a screen's worth of bitmap, mixed with a few much smaller tables (pgdim, pglinks, etc.), hence the / 3
|
|
avg_itemsize = math.floor(CanvasContext:getWidth() * CanvasContext:getHeight() * (CanvasContext.is_color_rendering_enabled and 4 or 1) / 3),
|
|
-- Rely on CacheItem's eviction callback to free resources *immediately* on eviction.
|
|
enable_eviction_cb = true,
|
|
disk_cache = true,
|
|
cache_path = DataStorage:getDataDir() .. "/cache/",
|
|
}
|
|
|
|
return DocCache
|