fix(avs): disable caching by 0s no longer causes an exception

This commit is contained in:
Steffen Jost 2024-02-19 10:49:31 +01:00
parent 57a4aeb475
commit d578e80282
3 changed files with 8 additions and 5 deletions

View File

@ -589,10 +589,11 @@ class SomeAvsQuery q where
avsQueryCached :: (SomeAvsQuery q, Binary q, Binary (SomeAvsResponse q), Typeable (SomeAvsResponse q), NFData (SomeAvsResponse q)
, MonadHandler m, HandlerSite m ~ UniWorX, MonadThrow m) => q -> m (SomeAvsResponse q)
avsQueryCached qry = do
cexpire <- getsYesod $ preview $ _appAvsConf . _Just . _avsCacheExpiry . to Right
memcachedBy cexpire qry $ avsQueryNoCache qry
avsQueryCached =
(getsYesod (preview $ _appAvsConf . _Just . _avsCacheExpiry) >>=) . flip (\case
(Just t) | t > 1 -> \qry -> memcachedBy (Just $ Right t) qry $ avsQueryNoCache qry
_ -> avsQueryNoCache
)
instance SomeAvsQuery AvsQueryPerson where
type SomeAvsResponse AvsQueryPerson = AvsResponsePerson

View File

@ -797,4 +797,4 @@ newtype AvsQuerySetLicences = AvsQuerySetLicences (Set AvsPersonLicence)
deriveJSON defaultOptions ''AvsQuerySetLicences
-- Note that separate types were need for Servant to fit the existing AVS/VSM-API.
-- See Utils.Avs.SomeAvsQuery for type class magic to provide a uniform interface to all queries.
-- See Handler.Utils.Avs.SomeAvsQuery for a type class to provide a uniform interface to all queries.

View File

@ -1713,6 +1713,8 @@ emptyHash = TH.liftTyped $ Crypto.hashFinalize Crypto.hashInit
-- Caching --
-------------
-- Note: uses yesod's cachedBy which is per-request caching only; use memcached instead for caching across multiple requests
cachedByBinary :: (Binary a, Typeable b, MonadHandler m) => a -> m b -> m b
cachedByBinary k = cachedBy (toStrict $ Binary.encode k)