packages feed

cached-json-file 0.1.0 → 0.1.1

raw patch · 4 files changed

+16/−10 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,5 +1,8 @@ # Version history for cached-json-file +## 0.1.1 (2021-12-27)+- pull new data if cache file is empty+ ## 0.1.0 (2021-07-29) - initial release with getCachedJSON and getCachedJSONQuery - exports lookupKey from http-query
README.md view
@@ -4,7 +4,7 @@  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.+where it is not critical to have always the latest data locally immediately.  ## Usage @@ -32,4 +32,4 @@ which uses `webquery :: (FromJSON a, ToJSON a) => IO a` to download the json data. -Currently the smallest possible cache time is 1 minute.+The shortest cache time is 1 minute.
cached-json-file.cabal view
@@ -1,5 +1,5 @@ name:                cached-json-file-version:             0.1.0+version:             0.1.1 synopsis:            Locally cache a json file obtained by http description:         A small library for caching a slow-changing remote json file in@@ -19,7 +19,7 @@                      ChangeLog.md cabal-version:       2.0 tested-with:         GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.4,-                     GHC == 8.10.4, GHC == 9.0.1+                     GHC == 8.10.5, GHC == 9.0.1  source-repository head   type:                git
src/System/Cached/JSON.hs view
@@ -16,8 +16,6 @@ import System.Environment.XDG.BaseDir import System.FilePath --- FIXME handle network failure- -- | If the local cached json file is new enough then use it, -- otherwise refresh from the remote url. getCachedJSON :: (FromJSON a, ToJSON a)@@ -44,10 +42,15 @@     putStrLn $ "Creating " ++ file ++ " ..."     createDirectoryIfMissing True (takeDirectory file)   recent <- do-    if exists then do-      ts <- getModificationTime file-      t <- getCurrentTime-      return $ diffUTCTime t ts < (minutes * 60)+    if exists+      then do+      size <- getFileSize file+      if size == 0+        then return False+        else do+        ts <- getModificationTime file+        t <- getCurrentTime+        return $ diffUTCTime t ts < (minutes * 60)       else return False   if recent     then do