Add config for sorted entries cache

optional
This commit is contained in:
Leeingnyo 2021-08-30 22:53:30 +09:00
parent bf81a4e48b
commit e988a8c121
3 changed files with 10 additions and 1 deletions

View File

@ -20,6 +20,8 @@ class Config
property plugin_path : String = File.expand_path "~/mango/plugins",
home: true
property download_timeout_seconds : Int32 = 30
property sorted_entries_cache_enable = false
property sorted_entries_cache_capacity_kbs = 51200
property disable_login = false
property default_username = ""
property auth_proxy_header_name = ""

View File

@ -178,10 +178,16 @@ end
# LRU Cache
class SortedEntriesCache
@@limit : Int128 = Int128.new 1024 * 1024 * 50 # 50MB
@@limit : Int128 = Int128.new 0
# key => entry
@@cache = {} of String => SortedEntriesCacheEntry
def self.init
enabled = Config.current.sorted_entries_cache_enable
cache_size = Config.current.sorted_entries_cache_capacity_kbs
@@limit = Int128.new cache_size * 1024 if enabled
end
def self.gen_key(book_id : String, username : String,
entries : Array(Entry), opt : SortOptions?)
sig = Digest::SHA1.hexdigest (entries.map &.id).to_s

View File

@ -55,6 +55,7 @@ class CLI < Clim
Config.load(opts.config).set_current
# Initialize main components
SortedEntriesCache.init
Storage.default
Queue.default
Library.default