From e7ac47d8e469817e02373a093f62e4735f7de281 Mon Sep 17 00:00:00 2001 From: Magnus Landerblom Date: Fri, 17 Jan 2025 11:36:46 +0100 Subject: [PATCH] convert ms to ns correctly --- src/lavinmq/deduplication.cr | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lavinmq/deduplication.cr b/src/lavinmq/deduplication.cr index 58869e41d2..d969240ba4 100644 --- a/src/lavinmq/deduplication.cr +++ b/src/lavinmq/deduplication.cr @@ -7,21 +7,26 @@ module LavinMQ class MemoryCache(T) < Cache(T) def initialize(@size : UInt32) - @store = Hash(T, Int64?).new + @store = Hash(T, Time::Span?).new end def contains?(key : T) : Bool return false unless @store.has_key?(key) ttd = @store[key] return true unless ttd - return true if ttd > RoughTime.unix_ms + return true if ttd > RoughTime.monotonic @store.delete(key) false end def insert(key : T, ttl : UInt32? = nil) @store.shift if @store.size >= @size - @store[key] = ttl ? RoughTime.unix_ms + ttl : nil + val = if ttl + RoughTime.monotonic + Time::Span.new(nanoseconds: ttl * 1_000_000) + else + nil + end + @store[key] = val end end