-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Secret can now be set on the command line
- Loading branch information
1 parent
b3a733d
commit e3c732c
Showing
5 changed files
with
99 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Changelog for local-managed-identity-haskell | ||
# Changelog for local-managed-identity | ||
|
||
## Unreleased changes | ||
|
||
## 1.0.0.0 | ||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,49 @@ | ||
{-# LANGUAGE InstanceSigs #-} | ||
{-# LANGUAGE KindSignatures #-} | ||
module LMI.Cache | ||
( Cache | ||
, newCache | ||
, readCache | ||
, putCache | ||
( Cache(..) | ||
, MVarCache | ||
, newMVarCache | ||
, NoCache | ||
, noCache | ||
) where | ||
|
||
import Control.Concurrent.MVar (MVar, readMVar, modifyMVar_, newMVar) | ||
import Control.Monad.IO.Class (MonadIO, liftIO) | ||
import Data.Map.Strict (Map) | ||
import qualified Data.Map.Strict as Map | ||
|
||
newtype Cache key value = Cache (MVar (Map key value)) | ||
class Cache (cache :: * -> * -> *) where | ||
readCache :: (MonadIO m, Ord key) => key -> cache key value -> m (Maybe value) | ||
putCache :: (MonadIO m, Ord key) => key -> value -> cache key value -> m () | ||
|
||
newCache :: MonadIO m => m (Cache key value) | ||
newCache = liftIO $ Cache <$> newMVar Map.empty | ||
|
||
readCache :: (MonadIO m, Ord key) => key -> Cache key value -> m (Maybe value) | ||
readCache key (Cache cacheMVar) = do | ||
liftIO $ Map.lookup key <$> readMVar cacheMVar | ||
newtype MVarCache key value = MVarCache (MVar (Map key value)) | ||
|
||
putCache :: (MonadIO m, Ord key) => key -> value -> Cache key value -> m () | ||
putCache key value (Cache cacheMVar) = do | ||
liftIO . modifyMVar_ cacheMVar $ \cache -> | ||
pure $ Map.insert key value cache | ||
instance Cache MVarCache where | ||
readCache :: (MonadIO m, Ord key) => key -> MVarCache key value -> m (Maybe value) | ||
readCache key (MVarCache cacheMVar) = do | ||
liftIO $ Map.lookup key <$> readMVar cacheMVar | ||
|
||
putCache :: (MonadIO m, Ord key) => key -> value -> MVarCache key value -> m () | ||
putCache key value (MVarCache cacheMVar) = do | ||
liftIO . modifyMVar_ cacheMVar $ \cache -> | ||
pure $ Map.insert key value cache | ||
|
||
newMVarCache :: MonadIO m => m (MVarCache key value) | ||
newMVarCache = liftIO $ MVarCache <$> newMVar Map.empty | ||
|
||
|
||
newtype NoCache key value = NoCache () | ||
|
||
instance Cache NoCache where | ||
readCache :: (MonadIO m) => key -> NoCache key value -> m (Maybe value) | ||
readCache key _ = do | ||
pure Nothing | ||
|
||
putCache :: (MonadIO m, Ord key) => key -> value -> NoCache key value -> m () | ||
putCache key value _ = do | ||
pure () | ||
|
||
noCache :: NoCache key value | ||
noCache = NoCache () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters