Skip to content

Commit

Permalink
Add config for sorted entries cache
Browse files Browse the repository at this point in the history
optional
  • Loading branch information
Leeingnyo committed Aug 30, 2021
1 parent bf81a4e commit e988a8c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
8 changes: 7 additions & 1 deletion src/library/cache.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/mango.cr
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CLI < Clim
Config.load(opts.config).set_current

# Initialize main components
SortedEntriesCache.init
Storage.default
Queue.default
Library.default
Expand Down

0 comments on commit e988a8c

Please sign in to comment.