getMintettesList
    :: C.WorkMode m
    => Maybe UserCache -> C.PeriodId -> m [C.Mintette]
getMintettesList maybeCache p =
    maybe loadAndCache return =<< tryCache maybeCache
  where
    tryCache Nothing = return Nothing
    tryCache (Just c) = do
        (storedPeriodId,storedMintettes) <-
            cdMintettes <$> liftIO (readTVarIO c)
        return $
            if storedPeriodId == p
                then Just storedMintettes
                else Nothing
    loadAndCache = do
        loaded <- C.getMintettes
        case maybeCache of
            Nothing -> return ()
            Just c ->
                liftIO . atomically $
                modifyTVar
                    c
                    (\cd ->
                          cd
                          { cdMintettes = (p, loaded)
                          })
        return loaded
getMintettesList
    :: C.WorkMode m
    => Maybe UserCache -> C.PeriodId -> m [C.Mintette]
getMintettesList maybeCache p =
    maybe loadAndCache return =<< tryCache maybeCache
  where
    tryCache Nothing = return Nothing
    tryCache (Just c) = do
        (storedPeriodId,storedMintettes) <-
            cdMintettes <$> liftIO (readTVarIO c)
        return $
            if storedPeriodId == p
                then Just storedMintettes
                else Nothing
    loadAndCache = do
        loaded <- C.getMintettes
        case maybeCache of
            Nothing -> return ()
            Just c ->
                liftIO . atomically $
                modifyTVar
                    c
                    (\cd ->
                          cd
                          { cdMintettes = (p, loaded)
                          })
        return loaded
getMintettesList maybeCache p =
    maybe loadAndCache return =<< tryCache maybeCache
  where
    tryCache Nothing = return Nothing
    tryCache (Just c) = do
        (storedPeriodId,storedMintettes) <-
            cdMintettes <$> liftIO (readTVarIO c)
        return $
            if storedPeriodId == p
                then Just storedMintettes
                else Nothing
    loadAndCache = do
        loaded <- C.getMintettes
        case maybeCache of
            Nothing -> return ()
            Just c ->
                liftIO . atomically $
                modifyTVar
                    c
                    (\cd ->
                          cd
                          { cdMintettes = (p, loaded)
                          })
        return loaded