From 835537ed834a5cd2d8da0921f5b930d899a2be85 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Thu, 16 Jul 2020 19:50:10 +0200 Subject: [PATCH] Send the right exception for missing entry. --- src/cached.cr | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cached.cr b/src/cached.cr index 2d961f5..33a53ba 100644 --- a/src/cached.cr +++ b/src/cached.cr @@ -1,3 +1,7 @@ +require "file_utils" +require "json" + +require "./dodb.cr" #class Hash(K,V) # def reverse @@ -37,6 +41,7 @@ class DODB::DataBase::Cached(V) self[index] = item self.last_index = index @data[self.last_index] = item + self.last_index end # Getting data from the hash in RAM. @@ -49,7 +54,7 @@ class DODB::DataBase::Cached(V) def [](key : Int32) : V # raise MissingEntry.new(key) unless ::File.exists? file_path key # read file_path key - @data[key] + @data[key] rescue raise MissingEntry.new(key) end def []=(index : Int32, value : V) @@ -301,4 +306,3 @@ class DODB::DataBase::Cached(V) end end end -