From ca33a035c779ae14fb6330c8801c75f49dd1bb79 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Sat, 7 Jan 2023 13:31:23 -0500 Subject: Add an internal caching option. It performs quite well. Also refactor and clean up most linter warnings. --- cmd/server/app.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'cmd/server/app.go') diff --git a/cmd/server/app.go b/cmd/server/app.go index 9a00628..c694753 100644 --- a/cmd/server/app.go +++ b/cmd/server/app.go @@ -7,14 +7,17 @@ import ( "github.com/gomodule/redigo/redis" "gopkg.in/yaml.v3" + "riedstra.dev/mitch/go-website/mapcache" "riedstra.dev/mitch/go-website/page" ) var FeedPrefixDefault = ".feeds" type App struct { + mapCache bool redisPool *redis.Pool RedisKey string + cache *mapcache.Cache ReIndexPath string StaticDirectory string @@ -86,6 +89,16 @@ func loadConf(fn string) (*App, error) { return app, nil } +func (a *App) ClearCache() error { + if a.redisPool != nil { + return a.ClearRedis() + } + + a.cache.Clear() + + return nil +} + // ClearRedis is a little helper function that allows us to easily clear // the redis cache at runtime. func (a *App) ClearRedis() error { -- cgit v1.2.3