cached-json-file: Locally cache a json file obtained by http

[ bsd3, library, network ] [ Propose Tags ]

A small library for caching a slow-changing remote json file in a specified directory (under "~/.cache/"). When the json is requested and the cache file is still fresh enough it is read directly from the local cache, otherwise the cached file is refreshed first.


[Skip to Readme]
Versions [RSS] [faq] 0.1.0
Change log ChangeLog.md
Dependencies aeson, base (<5), bytestring, directory, filepath, http-query, time, xdg-basedir [details]
License BSD-3-Clause
Copyright 2021 Jens Petersen <juhpetersen@gmail.com>
Author Jens Petersen <juhpetersen@gmail.com>
Maintainer Jens Petersen <juhpetersen@gmail.com>
Category Network
Home page https://github.com/juhp/cached-json-file
Bug tracker https://github.com/juhp/cached-json-file/issues
Source repo head: git clone https://github.com/juhp/cached-json-file.git
Uploaded by JensPetersen at 2021-07-29T06:31:18Z
Distributions LTSHaskell:0.1.0, NixOS:0.1.0, Stackage:0.1.0
Downloads 55 total (8 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2021-07-29 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Candidates


Readme for cached-json-file-0.1.0

[back to package description]

cached-json-file

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 immediately.

Usage

getCachedJSON dir file url minutes caches the json obtained from url in ~/.cache/dir/file for minutes.

eg:

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 ~/.cache/stackage-snapshots/snapshots.json 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 which uses webquery :: (FromJSON a, ToJSON a) => IO a to download the json data.

Currently the smallest possible cache time is 1 minute.