summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Internal')
-rw-r--r--src/Network/BitTorrent/Internal/Cache.hs14
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
34import Control.Applicative 34import Control.Applicative
35import Data.Aeson
35import Data.Monoid 36import Data.Monoid
36import Data.Default 37import Data.Default
37import Data.Time 38import 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
60instance 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
58instance Default (Cached a) where 72instance Default (Cached a) where
59 def = mempty 73 def = mempty
60 74