polling-cache 0.0.1.0 → 0.1.1.0
raw patch · 5 files changed
+33/−29 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Cache.Polling: cachedValues :: MonadCache m => PollingCache a -> m (CacheResult a)
+ Data.Cache.Polling: cachedValue :: MonadCache m => PollingCache a -> m (CacheResult a)
Files
- ChangeLog.org +4/−0
- README.org +1/−1
- polling-cache.cabal +1/−1
- src/Data/Cache/Polling.hs +3/−3
- test/PollingCacheSpec.hs +24/−24
ChangeLog.org view
@@ -2,6 +2,10 @@ * Unreleased changes +* 0.0.1.0 | 2021-08-01+** Changed+ - cachedValues renamed to cachedValue to reflect that only a single value is cached+ * 0.0.1.0 | 2021-07-31 ** Added - Initial public API
README.org view
@@ -47,7 +47,7 @@ let opts = basicOptions (DelayForMicroseconds 3600000000) Ignore cache <- newPollingCache opts dataGenerator threadDelay 100 -- Give the runtime a bit of time to execute the action in the background- latestResult <- cachedValues cache+ latestResult <- cachedValue cache print latestResult stopPolling cache -- Shut down and invalidate the cache
polling-cache.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: polling-cache-version: 0.0.1.0+version: 0.1.1.0 license: BSD3 license-file: LICENSE copyright: 2021 Jordan Kaye
src/Data/Cache/Polling.hs view
@@ -22,7 +22,7 @@ -- * Functions for creating and interacting with caches basicOptions, newPollingCache,- cachedValues,+ cachedValue, stopPolling, ) where@@ -142,8 +142,8 @@ handleDelay delayMode delayFuzzing result -- | Retrieve the current values from a 'PollingCache'.-cachedValues :: MonadCache m => PollingCache a -> m (CacheResult a)-cachedValues = readTVarIO . mostRecentValues+cachedValue :: MonadCache m => PollingCache a -> m (CacheResult a)+cachedValue = readTVarIO . mostRecentValues -- | Stops the background processing thread associated with a 'PollingCache'. --
test/PollingCacheSpec.hs view
@@ -113,30 +113,30 @@ let testCache = newPollingCache (testOptions 100 Ignore) alwaysSucceeds it "will suspend background execution for the time span specified by the user" $ do cache <- evalStateT testCache $ testState 4- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (123, testTime 300) describe "after stopping cache" $ do it "will no longer return valid values" $ do cache <- newPollingCache (testOptions 100 Ignore) alwaysSucceedsIO stopPolling cache- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Left Stopped describe "IO actions" $ do it "will be executed in a background thread" $ do cache <- newPollingCache (testOptions 1 Ignore) alwaysSucceedsIO threadDelay 100- val <- cachedValues cache+ val <- cachedValue cache val `shouldSatisfy` isRight stopPolling cache it "will execute repeatedly" $ do cache <- newPollingCache (testOptions 1 Ignore) alwaysSucceedsIO threadDelay 100- firstVal <- cachedValues cache+ firstVal <- cachedValue cache threadDelay 100- secondVal <- cachedValues cache+ secondVal <- cachedValue cache (firstVal <&> snd) `shouldNotBe` (secondVal <&> snd) stopPolling cache @@ -147,14 +147,14 @@ let testCache = newPollingCache (testOptions 10 Ignore) alwaysFails it "will never load a value" $ do cache <- evalStateT testCache $ testState 10- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Left NotYetLoaded describe "after succeeding once" $ do let testCache = newPollingCache (testOptions 10 Ignore) secondPassSucceeds it "will always return the successful result" $ do cache <- evalStateT testCache $ testState 10- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (12190, testTime 10) evictImmediatelySpec :: Spec@@ -164,29 +164,29 @@ let testCache = newPollingCache (testOptions 10 EvictImmediately) alwaysSucceeds it "will continually return the generated value" $ do (cache, st) <- runStateT testCache $ testState 1- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (123, testTime 0) nextCache <- evalStateT testCache st- nextVal <- cachedValues nextCache+ nextVal <- cachedValue nextCache nextVal `shouldBe` Right (123, testTime 10) describe "with a sporadic failure" $ do let testCache = newPollingCache (testOptions 10 EvictImmediately) secondPassFails it "will report the failure" $ do cache <- evalStateT testCache $ testState 2- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` (Left . LoadFailed $ testTime 10) it "will succeed after failure" $ do cache <- evalStateT testCache $ testState 10- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (234, testTime 90) describe "with a persistent failure" $ do let testCache = newPollingCache (testOptions 10 EvictImmediately) alwaysFails it "will not update the original failure time" $ do cache <- evalStateT testCache $ testState 10- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` (Left . LoadFailed $ testTime 0) evictAfterTimeSpec :: Spec@@ -196,22 +196,22 @@ let testCache = newPollingCache (testOptions 10 (EvictAfterTime 30)) (transientFailure 3 8) it "will not report the failure before the cut-off period" $ do cache <- evalStateT testCache $ testState 2- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (81590, testTime 10) it "will report the failure after the cut-off period" $ do cache <- evalStateT testCache $ testState 5- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` (Left . LoadFailed $ testTime 40) it "will not overwrite the failure time for successive failures" $ do cache <- evalStateT testCache $ testState 7- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` (Left . LoadFailed $ testTime 40) it "will report success after the failure subsides" $ do cache <- evalStateT testCache $ testState 10- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (81590, testTime 90) testDynamicDelay :: Int -> Either SomeException a -> Int@@ -224,12 +224,12 @@ describe "with a successful result" $ do it "will delay for the user's supplied time span" $ do cache <- evalStateT (testCache alwaysSucceeds) ts- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (123, testTime 15) describe "with an exception" $ do it "will delay for the user's supplied time span" $ do cache <- evalStateT (testCache secondPassFails) ts- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` (Left . LoadFailed $ testTime 15) delayDynamicallyWithBoundsSpec :: Spec@@ -239,24 +239,24 @@ describe "with a successful result" $ do it "will delay for the user's supplied time span" $ do cache <- evalStateT (testCache alwaysSucceeds) ts- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (123, testTime 10) describe "with an exception" $ do it "will delay for the user's supplied time span" $ do cache <- evalStateT (testCache secondPassFails) ts- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` (Left . LoadFailed $ testTime 10) describe "with a dynamic delay less than the lower bound" $ do let c = newPollingCache (testOptions' (DelayDynamicallyWithBounds (5, 15) $ testDynamicDelay 1) EvictImmediately ts) it "will delay for the lower bound" $ do cache <- evalStateT (c alwaysSucceeds) ts- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (123, testTime 5) describe "with a dynamic delay greater than the upper bound" $ do let c = newPollingCache (testOptions' (DelayDynamicallyWithBounds (5, 15) $ testDynamicDelay 25) EvictImmediately ts) it "will delay for upper bound" $ do cache <- evalStateT (c alwaysSucceeds) ts- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (123, testTime 15) fuzzingSpec :: Spec@@ -266,11 +266,11 @@ let testCache = newPollingCache (testOptions' (DelayForMicroseconds 11) EvictImmediately ts) it "will modify the delay period" $ do cache <- evalStateT (testCache alwaysSucceeds) ts- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (123, testTime 18) describe "with a dynamic delay" $ do let testCache = newPollingCache (testOptions' (DelayDynamically $ testDynamicDelay 17) EvictImmediately ts) it "will modify the delay period" $ do cache <- evalStateT (testCache alwaysSucceeds) ts- val <- cachedValues cache+ val <- cachedValue cache val `shouldBe` Right (123, testTime 24)