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
3a4ca20309
commit
c847e357f9
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
|
abstract class ItemStore
|
||||||
# Retrieves an item from the store
|
# Retrieves an item from the store
|
||||||
# Returns nil if item wasn't found or is expired
|
# 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
|
# 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
|
# Prematurely deletes item(s) from the cache
|
||||||
abstract def delete(key : String)
|
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
|
def initialize
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch(key : String, *, as : T.class) : T? forall T
|
def fetch(key : String) : String?
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def store(key : String, value : CacheableItem, expires : Time::Span)
|
def store(key : String, value : CacheableItem | String, expires : Time::Span)
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(key : String)
|
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
|
module Invidious::Cache
|
||||||
class RedisItemStore < ItemStore
|
class RedisItemStore < ItemStore
|
||||||
@redis : Redis::PooledClient
|
@redis : Redis::PooledClient
|
||||||
@node_name : String
|
|
||||||
|
|
||||||
def initialize(url : URI, @node_name = "")
|
def initialize(url : URI)
|
||||||
@redis = Redis::PooledClient.new url
|
@redis = Redis::PooledClient.new(url: url.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch(key : String, *, as : T.class) : (T | Nil) forall T
|
def fetch(key : String) : String?
|
||||||
value = @redis.get(key)
|
return @redis.get(key)
|
||||||
return nil if value.nil?
|
|
||||||
return T.from_json(JSON::PullParser.new(value))
|
|
||||||
end
|
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)
|
@redis.set(key, value, ex: expires.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,3 +38,7 @@ end
|
|||||||
# some important informations, and that the query should be sent again.
|
# some important informations, and that the query should be sent again.
|
||||||
class RetryOnceException < Exception
|
class RetryOnceException < Exception
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Exception used to indicate that the config file contains some errors
|
||||||
|
class InvalidConfigException < Exception
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user