Skip to content

Commit

Permalink
create cache on startup instead every time the cache is hit
Browse files Browse the repository at this point in the history
  • Loading branch information
froehlichA committed Apr 18, 2022
1 parent 9fa27af commit 2473597
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/api/cfcache.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@
import std/[json, options, os, times]

const
cacheDir* = getCacheDir("pax") ## the cache folder
addonCacheTime = 30.minutes ## how long an addon is cached
addonFileCacheTime = 1.days ## how long an addon file is cached

proc getPaxCacheDir(): string =
## returns the cache dir of pax.
return getCacheDir("pax")

proc getAddonFilename*(projectId: int): string {.inline.} =
## get the filename of an addon in the cache.
return getPaxCacheDir() / ("addon:" & $projectId)
return cacheDir / ("addon:" & $projectId)

proc getAddonFileFilename*(fileId: int): string {.inline.} =
## get the filename of an addon file in the cache.
return getPaxCacheDir() / ("file:" & $fileId)
return cacheDir / ("file:" & $fileId)

proc putAddon*(json: JsonNode): void =
## put an addon in the cache.
createDir(getPaxCacheDir())
let projectId = json["id"].getInt()
let filename = getAddonFilename(projectId)
writeFile(filename, $json)
Expand All @@ -37,7 +33,6 @@ proc putAddons*(json: JsonNode): void =

proc putAddonFile*(json: JsonNode): void =
## put an addon file in the cache.
createDir(getPaxCacheDir())
let fileId = json["id"].getInt()
let filename = getAddonFileFilename(fileId)
writeFile(filename, $json)
Expand Down
3 changes: 3 additions & 0 deletions src/pax.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import std/os
import therapist
import api/cfcache
import cmd/add, cmd/expo, cmd/impo, cmd/init, cmd/list, cmd/pin, cmd/remove, cmd/update, cmd/upgrade, cmd/version
import term/color, term/prompt
import util/paxVersion
Expand Down Expand Up @@ -199,6 +201,7 @@ let spec = (
)

spec.parseOrHelp()
createDir(cfcache.cacheDir)

# GLOBAL OPTIONS
if commonArgs.yes.seen:
Expand Down

0 comments on commit 2473597

Please sign in to comment.