From c105b7fa338de1e43ddd7a30eb686f9766ccda85 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Tue, 28 May 2024 03:28:40 +0200 Subject: [PATCH] Fix Common implementation. --- src/dodb/storage/common.cr | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dodb/storage/common.cr b/src/dodb/storage/common.cr index 0857967..744a25d 100644 --- a/src/dodb/storage/common.cr +++ b/src/dodb/storage/common.cr @@ -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