diff options
author | Vincent Ambo <tazjin@google.com> | 2019-08-21T10·07+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-08-21T10·07+0100 |
commit | 008be5c2e195761167b51c4c4b6bd1527fd9d854 (patch) | |
tree | 3991880d65b0a32cc2afd039e62e58d4e7f3e4cd /services/tazblog/src/BlogStore.hs | |
parent | bf2efeba2d5772ba1853ec5875c3c2faf02f1b07 (diff) |
refactor(tazblog): Directly instantiate Resolver when launching r/48
Caching behaviour is tied to the resolver.
Diffstat (limited to 'services/tazblog/src/BlogStore.hs')
-rw-r--r-- | services/tazblog/src/BlogStore.hs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/services/tazblog/src/BlogStore.hs b/services/tazblog/src/BlogStore.hs index e4c7a64b2634..17149ef86a8e 100644 --- a/services/tazblog/src/BlogStore.hs +++ b/services/tazblog/src/BlogStore.hs @@ -15,12 +15,21 @@ -- -- This module implements logic for assembling a post out of these -- fragments and caching it based on the TTL of its `_meta` record. -module BlogStore where +module BlogStore( + BlogCache, + EntryId(..), + Entry(..), + withCache, + listEntries, + getEntry, +) where import Control.Monad.IO.Class (MonadIO) import Data.Text (Text) import Data.Time (UTCTime) import Locales (BlogLang (..)) +import Network.DNS.Lookup (lookupTXT) +import qualified Network.DNS.Resolver as R newtype EntryId = EntryId {unEntryId :: Integer} deriving (Eq, Ord) @@ -41,17 +50,26 @@ data Entry } deriving (Eq, Ord, Show) +-- | Wraps a DNS resolver with caching configured. For the initial +-- version of this, all caching of entries is done by the resolver +-- (i.e. no pre-assembled versions of entries are cached). data BlogCache + = BlogCache { resolver :: R.Resolver + , zone :: String } type Offset = Integer type Count = Integer -newCache :: String -> IO BlogCache -newCache zone = undefined +withCache :: String -> (BlogCache -> IO a) -> IO a +withCache zone f = do + let conf = R.defaultResolvConf { R.resolvCache = Just R.defaultCacheConf + , R.resolvConcurrent = True } + seed <- R.makeResolvSeed conf + R.withResolver seed $ (\r -> f $ BlogCache r zone) listEntries :: MonadIO m => BlogCache -> Offset -> Count -> m [Entry] -listEntries cache offset count = undefined +listEntries (BlogCache r z) offset count = undefined getEntry :: MonadIO m => BlogCache -> EntryId -> m (Maybe Entry) -getEntry cache eId = undefined +getEntry (BlogCache r z) eId = undefined |