muesli-0.1.0.1: A simple document-oriented database

Copyright(c) 2015 Călin Ardelean
LicenseMIT
MaintainerCălin Ardelean <calinucs@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010
Extensions
  • BangPatterns
  • TupleSections

Database.Muesli.Cache

Description

LRU cache implementation using the psqueues package.

This module should be imported qualified.

Synopsis

Documentation

data DynValue Source

Holds a Dynamic and the size of the corresponding serialized data.

Constructors

DynValue 

Fields

dynValue :: !Dynamic
 
dynSize :: !Int
 

Instances

data LRUCache Source

A LRU cache that uses a lower capacity in periods of inactivity. This behaviour would be useful for things like long lived Android services.

Constructors

LRUCache 

Fields

minCapacity :: !Int

Minimum capacity under which maxAge is ignored

maxCapacity :: !Int

Maximum capacity above which oldest items are removed

maxAge :: !NominalDiffTime
 
size :: !Int

Current size (in bytes) of the cache

queue :: !(IntPSQ UTCTime DynValue)
 

empty Source

Arguments

:: Int

Minimum capacity (in bytes)

-> Int

Maximum capacity (in bytes)

-> NominalDiffTime

Maximum age (in seconds)

-> LRUCache 

Creates an empty cache.

insert Source

Arguments

:: Typeable a 
=> UTCTime

Current time

-> Int

Key

-> a

Value

-> Int

Size (in bytes)

-> LRUCache 
-> LRUCache 

Adds a new item to the cache, and trims.

lookup Source

Arguments

:: Typeable a 
=> UTCTime

Current time

-> Int

Key

-> LRUCache 
-> Maybe (a, Int, LRUCache) 

Looks up an item into the cache. If found, it updates the access time for the item, and then trims.

delete Source

Arguments

:: Int

Key

-> LRUCache 
-> LRUCache 

Deletes an item from the cache.

trim Source

Arguments

:: UTCTime

Current time

-> LRUCache 
-> LRUCache 

Apply cache's policy and removes items if necessary.