Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/juhp/cached-json-file
https://github.com/juhp/cached-json-file
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/juhp/cached-json-file
- Owner: juhp
- License: bsd-3-clause
- Created: 2021-07-02T17:09:00.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-14T11:14:56.000Z (almost 3 years ago)
- Last Synced: 2024-10-12T18:56:07.181Z (27 days ago)
- Language: Haskell
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# 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 locally immediately.## Usage
`getCachedJSON dir file url minutes` caches the json obtained from `url` in
`~/.cache/dir/file` for `minutes`.eg:
```haskell
import System.Cached.JSONgetSnapshots :: IO Object
getSnapshots =
getCachedJSON "stackage-snapshots" "snapshots.json" "http://haddock.stackage.org/snapshots.json" 180main = 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.The shortest cache time is 1 minute.