Fix Common implementation.
parent
279f4379e8
commit
c105b7fa33
|
@ -33,7 +33,7 @@
|
|||
#
|
||||
# NOTE: fast for frequently requested data and requires a stable (and configurable) amount of memory.
|
||||
class DODB::Storage::Common(V) < DODB::Storage::Cached(V)
|
||||
# The *fifo* an `EfficientFIFO` instance where the key of the requested data is pushed.
|
||||
# The *fifo* is an instance of `EfficientFIFO` where the key of the requested data is pushed.
|
||||
# In case the number of stored entries exceeds what is allowed, the least recently used entry is removed.
|
||||
property fifo : EfficientFIFO(Int32)
|
||||
|
||||
|
@ -50,8 +50,15 @@ class DODB::Storage::Common(V) < DODB::Storage::Cached(V)
|
|||
end
|
||||
end
|
||||
|
||||
# Verifies that the value is in cache, or read it on disk.
|
||||
# Pushes the key in the fifo.
|
||||
def [](key : Int32) : V
|
||||
val = @data[key] rescue raise MissingEntry.new(key)
|
||||
val = @data[key]?
|
||||
if val.nil?
|
||||
raise MissingEntry.new(key) unless ::File.exists? file_path key
|
||||
val = read file_path key
|
||||
@data[key] = val
|
||||
end
|
||||
push_fifo key
|
||||
val
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue