aboutsummaryrefslogtreecommitdiff
path: root/internal/liturgy/fetch.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/liturgy/fetch.go')
-rw-r--r--internal/liturgy/fetch.go32
1 files changed, 19 insertions, 13 deletions
diff --git a/internal/liturgy/fetch.go b/internal/liturgy/fetch.go
index f4f6992..8c887f4 100644
--- a/internal/liturgy/fetch.go
+++ b/internal/liturgy/fetch.go
@@ -41,11 +41,13 @@ var publishedRe = regexp.MustCompile(`id="\w*0all"`)
// validate its own input first.
var dateRe = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}$`)
-// cacheFileRe matches the cache file names Load/Harvest write into
-// cacheDir(): "<YYYY-MM-DD>.html" or "<YYYY-MM-DD>.json". CleanCache uses it
-// to tell cache entries apart from anything else that might be sitting in
-// the directory.
-var cacheFileRe = regexp.MustCompile(`^(\d{4}-\d{2}-\d{2})\.(html|json)$`)
+// cacheFileRe matches the date-prefixed cache file names Load/Harvest/tradlit
+// write into CacheDir(): "<YYYY-MM-DD>.html", "<YYYY-MM-DD>.json", and
+// "<YYYY-MM-DD>.trad.<lang>.json" (the traditional-lectionary cache; see
+// internal/tradlit). CleanCache uses it to tell cache entries apart from
+// anything else that might be sitting in the directory, and to recover the
+// date (group 1) for the age check regardless of which cache file it is.
+var cacheFileRe = regexp.MustCompile(`^(\d{4}-\d{2}-\d{2})\.[a-z0-9.]+$`)
// Options controls how Load resolves a day's readings.
type Options struct {
@@ -58,9 +60,11 @@ type Options struct {
Offline bool
}
-// cacheDir is where the HTML/JSON cache layers live:
+// CacheDir is where the HTML/JSON cache layers live:
// ${XDG_CACHE_HOME:-~/.cache}/lectio/
-func cacheDir() string {
+// Exported so internal/tradlit shares the same cache root for the
+// traditional lectionary's propers.
+func CacheDir() string {
base := os.Getenv("XDG_CACHE_HOME")
if base == "" {
home, err := os.UserHomeDir()
@@ -93,7 +97,7 @@ func Load(opts Options) ([]Section, error) {
return LoadOffline(opts.Date)
}
- dir := cacheDir()
+ dir := CacheDir()
jsonPath := filepath.Join(dir, opts.Date+".json")
htmlPath := filepath.Join(dir, opts.Date+".html")
@@ -142,12 +146,14 @@ func Load(opts Options) ([]Section, error) {
}
// CleanCache removes cached readings whose date is before `before` from
-// cacheDir(). It matches only files named "<YYYY-MM-DD>.html"/".json";
-// anything else in the directory (e.g. a stray notes.txt, or the sigla
-// store, which lives elsewhere entirely) is left alone. A missing cache dir
-// is not an error -- it just means there is nothing to clean yet.
+// CacheDir(). It matches only date-prefixed cache files (see cacheFileRe:
+// "<YYYY-MM-DD>.html", ".json", or the traditional lectionary's
+// ".trad.<lang>.json"); anything else in the directory (e.g. a stray
+// notes.txt, or the sigla store, which lives elsewhere entirely) is left
+// alone. A missing cache dir is not an error -- it just means there is
+// nothing to clean yet.
func CleanCache(before time.Time) (removed int, freed int64, err error) {
- dir := cacheDir()
+ dir := CacheDir()
entries, err := os.ReadDir(dir)
if err != nil {
if os.IsNotExist(err) {