lazy-cache-0.2.0.0: Library for caching IO action that leverages on GHC RTS implementation
Safe HaskellNone
LanguageHaskell2010

System.Cache.Impl.Ghc

Description

Caching based on the GHC heap object properties and relies on lazyness implementation in the GHC RTS. This approach does it's best effort for avoiding the duplicated work, however it the pathological cases it's possible that two theads will run the computation on the same input concurrently. We have not observed this case in practice, but in the case if you need strict guarantees on this property you should use System.Cache.Impl.MVar instead.

This is battle-tested implementation. That fits all the properties that are required by the interface.

Synopsis

Documentation

new :: (Show a, Hashable a, Ord a) => Config -> IO (Handle a b) Source #

Creates new cache Handle. Keeps priotity queue from psqueues package inside.

Properties:

  • if multiple threads are running an IO action with the same input concurrently then only one (with the best effort) will run, all the rest will wait for that action and will either return a value, or throw an exception depending on the the result of the first one
  • storage is cleared only during access, it will remove redundant work but may lead to the situation when cached values are stored in memory for a longer period that it was expected
  • psqueue structure uses both Hashable and Ord constraints and is not vulnerable to the hash collision attacks.