diff options
Diffstat (limited to 'src/Network/BitTorrent/Internal')
-rw-r--r-- | src/Network/BitTorrent/Internal/Cache.hs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Internal/Cache.hs b/src/Network/BitTorrent/Internal/Cache.hs index 8c74467a..b77e5e82 100644 --- a/src/Network/BitTorrent/Internal/Cache.hs +++ b/src/Network/BitTorrent/Internal/Cache.hs | |||
@@ -32,6 +32,7 @@ module Network.BitTorrent.Internal.Cache | |||
32 | ) where | 32 | ) where |
33 | 33 | ||
34 | import Control.Applicative | 34 | import Control.Applicative |
35 | import Data.Aeson | ||
35 | import Data.Monoid | 36 | import Data.Monoid |
36 | import Data.Default | 37 | import Data.Default |
37 | import Data.Time | 38 | import Data.Time |
@@ -55,6 +56,19 @@ data Cached a = Cached | |||
55 | 56 | ||
56 | -- INVARIANT: minUpdateInterval <= updateInterval | 57 | -- INVARIANT: minUpdateInterval <= updateInterval |
57 | 58 | ||
59 | -- | TODO exsample | ||
60 | instance ToJSON a => ToJSON (Cached a) where | ||
61 | toJSON Cached {..} | ||
62 | | currentTime < expireTime = object | ||
63 | [ "observed" .= posixSecondsToUTCTime lastUpdated | ||
64 | , "expired" .= posixSecondsToUTCTime expireTime | ||
65 | , "data" .= cachedData | ||
66 | ] | ||
67 | | otherwise = String "cached data expired" | ||
68 | where | ||
69 | expireTime = currentTime + updateInterval | ||
70 | currentTime = unsafePerformIO getPOSIXTime | ||
71 | |||
58 | instance Default (Cached a) where | 72 | instance Default (Cached a) where |
59 | def = mempty | 73 | def = mempty |
60 | 74 | ||