diff --git a/src/Handler/Utils/Avs.hs b/src/Handler/Utils/Avs.hs index ee51c2672..c0ca02048 100644 --- a/src/Handler/Utils/Avs.hs +++ b/src/Handler/Utils/Avs.hs @@ -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 diff --git a/src/Model/Types/Avs.hs b/src/Model/Types/Avs.hs index 82fc54f7d..f857dd12f 100644 --- a/src/Model/Types/Avs.hs +++ b/src/Model/Types/Avs.hs @@ -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. \ No newline at end of file +-- See Handler.Utils.Avs.SomeAvsQuery for a type class to provide a uniform interface to all queries. \ No newline at end of file diff --git a/src/Utils.hs b/src/Utils.hs index 79a7bfd66..0e0c3db04 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -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)