File: InvalidateTestOrdECM.hs

package info (click to toggle)
haskell-expiring-cache-map 0.0.6.1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 232 kB
  • sloc: haskell: 2,209; makefile: 5
file content (50 lines) | stat: -rw-r--r-- 1,964 bytes parent folder | download | duplicates (5)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{-# LANGUAGE OverloadedStrings #-}

module InvalidateTestOrdECM (
    tests
) where

import Caching.ExpiringCacheMap.OrdECM (newECMIO, lookupECM, CacheSettings(..), consistentDuration)
import qualified Caching.ExpiringCacheMap.OrdECM as ECM (invalidate, invalidateCache, keysCached, keysNotExpired)

import InvalidateTestCommon (test1Common, test2Common)

import qualified Data.Time.Clock.POSIX as POSIX (POSIXTime, getPOSIXTime)
import qualified Data.ByteString.Char8 as BS
import Data.Time.Clock
import Control.Concurrent (threadDelay)


tests = do
  test1
  test2
  return ()

test1 = do
  filecache1 <- newECMIO
        (consistentDuration 100
          (\state id -> do BS.putStrLn "Reading a file again..."
                           return (state, ("file contents" :: BS.ByteString) )))
        (return 1)
        12000 -- Value to modulo with cache state accumulator to determine time check frequency.
        (CacheWithLRUList
          100     -- Expected size of key-value map when removing elements.
          100     -- Size at when to remove items from key-value map.
          200 )
  test1Common (lookupECM filecache1) (ECM.invalidate filecache1) (ECM.keysCached filecache1) (ECM.invalidateCache filecache1)
  return ()

test2 = do
  filecache2 <- newECMIO
        (consistentDuration 0
          (\state id -> do BS.putStrLn "Reading a file again..."
                           return (state, ("file contents" :: BS.ByteString) )))
        (do time <- POSIX.getPOSIXTime
            return (round (time * 100)))
        1 -- Value to modulo with cache state accumulator to determine time check frequency.
        (CacheWithLRUList
          6     -- Expected size of key-value map when removing elements.
          6     -- Size at when to remove items from key-value map.
          12 )
  test2Common (lookupECM filecache2) (ECM.keysCached filecache2) (ECM.keysNotExpired filecache2)
  return ()