mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-08 13:42:27 +05:30
temp fix, while cacheable item is not integrated
This commit is contained in:
parent
eeda9b5dba
commit
2a3dca6b1f
4
src/invidious/cache/item_store.cr
vendored
4
src/invidious/cache/item_store.cr
vendored
@ -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)
|
||||
|
4
src/invidious/cache/null_item_store.cr
vendored
4
src/invidious/cache/null_item_store.cr
vendored
@ -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)
|
||||
|
14
src/invidious/cache/redis_item_store.cr
vendored
14
src/invidious/cache/redis_item_store.cr
vendored
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user