Locally cache a json file obtained by http
|LTS Haskell 20.16:||0.1.1|
|Stackage Nightly 2023-03-28:||0.1.1|
|Latest on Hackage:||0.1.1|
Module documentation for 0.1.1
A Haskell library providing a cached json file.
Useful for frequently used programs that use some remote json data which changes rather slowly (like in hours, days, weeks or months), where it is not critical to have always the latest data locally immediately.
getCachedJSON dir file url minutes caches the json obtained from
import System.Cached.JSON getSnapshots :: IO Object getSnapshots = getCachedJSON "stackage-snapshots" "snapshots.json" "http://haddock.stackage.org/snapshots.json" 180 main = getSnapshots >>= print
Each time you run this program within 3 hours the data will be read
from the local cache file
rather than re-downloading it each time,
which helps to speed up the program and avoid unnecessary web queries.
There is also
getCachedJSONQuery prog jsonfile webquery minutes
webquery :: (FromJSON a, ToJSON a) => IO a to download
the json data.
The shortest cache time is 1 minute.
Version history for cached-json-file
- pull new data if cache file is empty
- initial release with getCachedJSON and getCachedJSONQuery
- exports lookupKey from http-query