summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/BitTorrent/Internal/Cache.hs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/Network/BitTorrent/Internal/Cache.hs b/src/Network/BitTorrent/Internal/Cache.hs
index b77e5e82..5c3f379b 100644
--- a/src/Network/BitTorrent/Internal/Cache.hs
+++ b/src/Network/BitTorrent/Internal/Cache.hs
@@ -56,15 +56,26 @@ data Cached a = Cached
56 56
57-- INVARIANT: minUpdateInterval <= updateInterval 57-- INVARIANT: minUpdateInterval <= updateInterval
58 58
59-- | TODO exsample 59-- | Examples:
60--
61-- { data: "some string",
62-- observed: "2014-03-20T19:49:39.505Z",
63-- expires: "2014-03-20T19:50:10.881Z" }
64--
65-- or:
66--
67-- { expired: "2014-03-20T19:50:10.881Z" }
68--
60instance ToJSON a => ToJSON (Cached a) where 69instance ToJSON a => ToJSON (Cached a) where
61 toJSON Cached {..} 70 toJSON Cached {..}
62 | currentTime < expireTime = object 71 | currentTime < expireTime = object
63 [ "observed" .= posixSecondsToUTCTime lastUpdated 72 [ "observed" .= posixSecondsToUTCTime lastUpdated
64 , "expired" .= posixSecondsToUTCTime expireTime 73 , "expires" .= posixSecondsToUTCTime expireTime
65 , "data" .= cachedData 74 , "data" .= cachedData
66 ] 75 ]
67 | otherwise = String "cached data expired" 76 | otherwise = object
77 [ "expired" .= posixSecondsToUTCTime expireTime
78 ]
68 where 79 where
69 expireTime = currentTime + updateInterval 80 expireTime = currentTime + updateInterval
70 currentTime = unsafePerformIO getPOSIXTime 81 currentTime = unsafePerformIO getPOSIXTime