Skip to content

deviant-logic/cache-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

The idea here is that it’s necessary-but-painful to read in your big, convoluted file every time your program runs. It would be convenient if you could cache the value you read out of the file, and only do the painful file reading when the original big, convoluted file changes on the filesystem. So that’s what CacheFile does.

Example

import Data.CacheFile

painful_read :: FilePath -> IO SomeBinaryInstance
painful_read = ...

read_cached = cacheFile painful_read

main = do ouch <- read_cached "file"
          ahhh <- read_cached "file"
          return (ouch == ahhh)

Reading ouch will then, presumably, take an uncomfortably long amount of time. The read into ahhh pleasurably short (the speed of a decodeFile from Data.Binary).

The (few) details

The various cacheFile* functions check whether the file you want to read has already been cached, and if so, whether the cache is stale (just using mtime at the moment). If it is, it runs the original painful read, and caches the result. Otherwise, it just reads the cache file.

About

A Haskell library to cache the results of slow file reads

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published