packages feed

Concurrent-Cache 0.2.2.1 → 0.2.2.2

raw patch · 2 files changed

+18/−2 lines, 2 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Control.Concurrent.Cache: createCachePassthrough :: a -> CachedData a

Files

Concurrent-Cache.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                Concurrent-Cache-version:             0.2.2.1+version:             0.2.2.2 synopsis:            A Cached variable for IO functions. description:         This package allows for caching IO functions, either on a                      timeout or designed to only fetch once.
Control/Concurrent/Cache.hs view
@@ -1,4 +1,4 @@-module Control.Concurrent.Cache (CachedData, fetch, fetchCached, createReadOnceCache, createTimedCache) where+module Control.Concurrent.Cache (CachedData, fetch, fetchCached, createReadOnceCache, createTimedCache, createCachePassthrough) where  import Data.Maybe (isNothing) import Control.Concurrent (forkIO, threadDelay, killThread, MVar, modifyMVar_, readMVar, ThreadId, newMVar, mkWeakMVar)@@ -10,8 +10,10 @@  data CachedData a = TimedCachedData Timeout (TimedCachedDataMVar a) (Weak (TimedCachedDataMVar a))                     | ReadOnceCachedData (MVar (Either (IO a) a))+                    | CachePassthrough a  -- |Only fetch data if it has been cached.+-- @since 0.2.1.0 fetchCached :: CachedData a             -> IO (Maybe a) fetchCached (ReadOnceCachedData mvar) = do@@ -40,7 +42,10 @@               else return mvar'   return value +fetchCached (CachePassthrough a) = return $ Just a+ -- |Fetch data from a cache+-- @since 0.1.0.0 fetch :: CachedData a       -> IO (a) fetch state@(ReadOnceCachedData mvar) = go where@@ -66,9 +71,11 @@         go       Just value -> return value +fetch (CachePassthrough a) = return a  -- |Create a cache which will execute an (IO ()) function on demand -- a maximum of 1 times.+-- @since 0.2.0.0 createReadOnceCache  :: IO (a)             -- ^ @Fetcher@, the function that returns the data which should             -- be cached. @@ -78,6 +85,7 @@   return $ ReadOnceCachedData var  -- |Create a cache with a timeout from an (IO ()) function.+-- @since 0.2.0.0 createTimedCache  :: Int             -- ^ @Timeout@ in microseconds before the cache is erased             -> Bool@@ -96,3 +104,11 @@                    else TimeSinceCreation timeout   weakMVar <- mkWeakMVar var $ return ()   return $ TimedCachedData timeout' var weakMVar++-- |Create a cache variable which simply holds a value with no actual+-- caching at all.+-- @since 0.2.2.2+createCachePassthrough :: a+                       -- ^ @Variable@ to hold.+                       -> CachedData a+createCachePassthrough = CachePassthrough