mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 11:25:29 -04:00
Cache TitleInfo using LRUCache
This commit is contained in:
parent
de410f42b8
commit
847f516a65
@ -92,6 +92,18 @@ class TitleInfo
|
|||||||
@@mutex_hash = {} of String => Mutex
|
@@mutex_hash = {} of String => Mutex
|
||||||
|
|
||||||
def self.new(dir, &)
|
def self.new(dir, &)
|
||||||
|
key = "#{dir}:info.json"
|
||||||
|
info = LRUCache.get key
|
||||||
|
if info.is_a? String
|
||||||
|
begin
|
||||||
|
instance = TitleInfo.from_json info
|
||||||
|
instance.dir = dir
|
||||||
|
yield instance
|
||||||
|
return
|
||||||
|
rescue
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if @@mutex_hash[dir]?
|
if @@mutex_hash[dir]?
|
||||||
mutex = @@mutex_hash[dir]
|
mutex = @@mutex_hash[dir]
|
||||||
else
|
else
|
||||||
@ -105,6 +117,7 @@ class TitleInfo
|
|||||||
instance = TitleInfo.from_json File.read json_path
|
instance = TitleInfo.from_json File.read json_path
|
||||||
end
|
end
|
||||||
instance.dir = dir
|
instance.dir = dir
|
||||||
|
LRUCache.set generate_cache_entry key, instance.to_json
|
||||||
yield instance
|
yield instance
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -112,5 +125,7 @@ class TitleInfo
|
|||||||
def save
|
def save
|
||||||
json_path = File.join @dir, "info.json"
|
json_path = File.join @dir, "info.json"
|
||||||
File.write json_path, self.to_pretty_json
|
File.write json_path, self.to_pretty_json
|
||||||
|
key = "#{@dir}:info.json"
|
||||||
|
LRUCache.set generate_cache_entry key, self.to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user