From c847e357f90b874c8096e25031b6b011d78752d0 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Sun, 18 Jun 2023 13:09:12 +0200 Subject: [PATCH] temp fix, while cacheable item is not integrated --- src/invidious/cache/item_store.cr | 4 ++-- src/invidious/cache/null_item_store.cr | 4 ++-- src/invidious/cache/redis_item_store.cr | 14 ++++++-------- src/invidious/exceptions.cr | 4 ++++ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/invidious/cache/item_store.cr b/src/invidious/cache/item_store.cr index e4ec1201..ebe5b1f9 100644 --- a/src/invidious/cache/item_store.cr +++ b/src/invidious/cache/item_store.cr @@ -7,10 +7,10 @@ module Invidious::Cache abstract class ItemStore # Retrieves an item from the store # Returns nil if item wasn't found or is expired - abstract def fetch(key : String, *, as : T.class) + abstract def fetch(key : String) # Stores a given item into cache - abstract def store(key : String, value : CacheableItem, expires : Time::Span) + abstract def store(key : String, value : CacheableItem | String, expires : Time::Span) # Prematurely deletes item(s) from the cache abstract def delete(key : String) diff --git a/src/invidious/cache/null_item_store.cr b/src/invidious/cache/null_item_store.cr index c26c0804..0f599564 100644 --- a/src/invidious/cache/null_item_store.cr +++ b/src/invidious/cache/null_item_store.cr @@ -5,11 +5,11 @@ module Invidious::Cache def initialize end - def fetch(key : String, *, as : T.class) : T? forall T + def fetch(key : String) : String? return nil end - def store(key : String, value : CacheableItem, expires : Time::Span) + def store(key : String, value : CacheableItem | String, expires : Time::Span) end def delete(key : String) diff --git a/src/invidious/cache/redis_item_store.cr b/src/invidious/cache/redis_item_store.cr index ccf847a6..bd5550ef 100644 --- a/src/invidious/cache/redis_item_store.cr +++ b/src/invidious/cache/redis_item_store.cr @@ -5,19 +5,17 @@ require "redis" module Invidious::Cache class RedisItemStore < ItemStore @redis : Redis::PooledClient - @node_name : String - def initialize(url : URI, @node_name = "") - @redis = Redis::PooledClient.new url + def initialize(url : URI) + @redis = Redis::PooledClient.new(url: url.to_s) end - def fetch(key : String, *, as : T.class) : (T | Nil) forall T - value = @redis.get(key) - return nil if value.nil? - return T.from_json(JSON::PullParser.new(value)) + def fetch(key : String) : String? + return @redis.get(key) end - def store(key : String, value : CacheableItem, expires : Time::Span) + def store(key : String, value : CacheableItem | String, expires : Time::Span) + value = value.to_json if value.is_a?(CacheableItem) @redis.set(key, value, ex: expires.to_i) end diff --git a/src/invidious/exceptions.cr b/src/invidious/exceptions.cr index 690db907..bdbc0c49 100644 --- a/src/invidious/exceptions.cr +++ b/src/invidious/exceptions.cr @@ -38,3 +38,7 @@ end # some important informations, and that the query should be sent again. class RetryOnceException < Exception end + +# Exception used to indicate that the config file contains some errors +class InvalidConfigException < Exception +end