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

@@ -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