File: MemTest.hs

package info (click to toggle)
haskell-lrucache 1.2.0.0-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 104 kB
  • sloc: haskell: 391; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 564 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import Prelude hiding ( lookup )

import Control.Monad
import Control.Concurrent
import Data.IORef

import Data.Cache.LRU.IO.Internal

main :: IO ()
main = do
  v1 <- newAtomicLRU $ Just 10 -- for endless inserts
  v2 <- newAtomicLRU $ Just 10 -- for endless lookups (miss)
  v3 <- newAtomicLRU $ Just 10 -- for endless lookups (hit)

  counter <- newIORef (0 :: Int)

  insert 1 "bar" v3

  forever $ do
         c <- readIORef counter
         writeIORef counter $ c + 1

         insert c (show c) v1
         lookup (1 :: Int) v2
         lookup (1 :: Int) v3