summaryrefslogtreecommitdiff
path: root/internal/config/config.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2022-12-11 13:03:15 +0000
committerLibravatar GitHub <noreply@github.com>2022-12-11 13:03:15 +0000
commitcb2b2fd8058a71826f23f60036cb0232eee113c7 (patch)
tree761e6c0acc211c8ca9e8b957cd99d1e93668eebe /internal/config/config.go
parent[docs] Caching webfinger with nginx (#1242) (diff)
downloadgotosocial-cb2b2fd8058a71826f23f60036cb0232eee113c7.tar.xz
[feature] support configuring database caches (#1246)
* update config generator to support nested structs, add cache configuration options * update envparsing test * add cache configuration to config parse tests * set cache configuration in testrig * move caches to sub-cache "gts" namespace, update envparsing, add cache config docs to example config Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/config/config.go')
-rw-r--r--internal/config/config.go52
1 files changed, 51 insertions, 1 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 047765a75..8a2c041e1 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -20,6 +20,7 @@ package config
import (
"reflect"
+ "time"
"codeberg.org/gruf/go-bytesize"
"github.com/mitchellh/mapstructure"
@@ -129,6 +130,9 @@ type Configuration struct {
AdvancedCookiesSamesite string `name:"advanced-cookies-samesite" usage:"'strict' or 'lax', see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite"`
AdvancedRateLimitRequests int `name:"advanced-rate-limit-requests" usage:"Amount of HTTP requests to permit within a 5 minute window. 0 or less turns rate limiting off."`
+ // Cache configuration vars.
+ Cache CacheConfiguration `name:"cache"`
+
// TODO: move these elsewhere, these are more ephemeral vs long-running flags like above
AdminAccountUsername string `name:"username" usage:"the username to create/delete/etc"`
AdminAccountEmail string `name:"email" usage:"the email address of this account"`
@@ -137,7 +141,53 @@ type Configuration struct {
AdminMediaPruneDryRun bool `name:"dry-run" usage:"perform a dry run and only log number of items eligible for pruning"`
}
-// MarshalMap will marshal current Configuration into a map structure (useful for JSON).
+type CacheConfiguration struct {
+ GTS GTSCacheConfiguration `name:"gts"`
+}
+
+type GTSCacheConfiguration struct {
+ AccountMaxSize int `name:"account-max-size"`
+ AccountTTL time.Duration `name:"account-ttl"`
+ AccountSweepFreq time.Duration `name:"account-sweep-freq"`
+
+ BlockMaxSize int `name:"block-max-size"`
+ BlockTTL time.Duration `name:"block-ttl"`
+ BlockSweepFreq time.Duration `name:"block-sweep-freq"`
+
+ DomainBlockMaxSize int `name:"domain-block-max-size"`
+ DomainBlockTTL time.Duration `name:"domain-block-ttl"`
+ DomainBlockSweepFreq time.Duration `name:"domain-block-sweep-freq"`
+
+ EmojiMaxSize int `name:"emoji-max-size"`
+ EmojiTTL time.Duration `name:"emoji-ttl"`
+ EmojiSweepFreq time.Duration `name:"emoji-sweep-freq"`
+
+ EmojiCategoryMaxSize int `name:"emoji-category-max-size"`
+ EmojiCategoryTTL time.Duration `name:"emoji-category-ttl"`
+ EmojiCategorySweepFreq time.Duration `name:"emoji-category-sweep-freq"`
+
+ MentionMaxSize int `name:"mention-max-size"`
+ MentionTTL time.Duration `name:"mention-ttl"`
+ MentionSweepFreq time.Duration `name:"mention-sweep-freq"`
+
+ NotificationMaxSize int `name:"notification-max-size"`
+ NotificationTTL time.Duration `name:"notification-ttl"`
+ NotificationSweepFreq time.Duration `name:"notification-sweep-freq"`
+
+ StatusMaxSize int `name:"status-max-size"`
+ StatusTTL time.Duration `name:"status-ttl"`
+ StatusSweepFreq time.Duration `name:"status-sweep-freq"`
+
+ TombstoneMaxSize int `name:"tombstone-max-size"`
+ TombstoneTTL time.Duration `name:"tombstone-ttl"`
+ TombstoneSweepFreq time.Duration `name:"tombstone-sweep-freq"`
+
+ UserMaxSize int `name:"user-max-size"`
+ UserTTL time.Duration `name:"user-ttl"`
+ UserSweepFreq time.Duration `name:"user-sweep-freq"`
+}
+
+// MarshalMap will marshal current Configuration into a map structure (useful for JSON/TOML/YAML).
func (cfg *Configuration) MarshalMap() (map[string]interface{}, error) {
var dst map[string]interface{}
dec, _ := mapstructure.NewDecoder(&mapstructure.DecoderConfig{