summaryrefslogtreecommitdiff
path: root/internal/cache/db.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cache/db.go')
-rw-r--r--internal/cache/db.go70
1 files changed, 66 insertions, 4 deletions
diff --git a/internal/cache/db.go b/internal/cache/db.go
index c383ed6c7..cb0ed6712 100644
--- a/internal/cache/db.go
+++ b/internal/cache/db.go
@@ -58,6 +58,9 @@ type GTSCaches struct {
// BoostOfIDs provides access to the boost of IDs list database cache.
BoostOfIDs SliceCache[string]
+ // Client provides access to the gtsmodel Client database cache.
+ Client StructCache[*gtsmodel.Client]
+
// DomainAllow provides access to the domain allow database cache.
DomainAllow *domain.Cache
@@ -150,6 +153,9 @@ type GTSCaches struct {
// Tag provides access to the gtsmodel Tag database cache.
Tag StructCache[*gtsmodel.Tag]
+ // Token provides access to the gtsmodel Token database cache.
+ Token StructCache[*gtsmodel.Token]
+
// Tombstone provides access to the gtsmodel Tombstone database cache.
Tombstone StructCache[*gtsmodel.Tombstone]
@@ -309,9 +315,10 @@ func (c *Caches) initApplication() {
{Fields: "ID"},
{Fields: "ClientID"},
},
- MaxSize: cap,
- IgnoreErr: ignoreErrors,
- Copy: copyF,
+ MaxSize: cap,
+ IgnoreErr: ignoreErrors,
+ Copy: copyF,
+ Invalidate: c.OnInvalidateApplication,
})
}
@@ -374,6 +381,32 @@ func (c *Caches) initBoostOfIDs() {
c.GTS.BoostOfIDs.Init(0, cap)
}
+func (c *Caches) initClient() {
+ // Calculate maximum cache size.
+ cap := calculateResultCacheMax(
+ sizeofClient(), // model in-mem size.
+ config.GetCacheClientMemRatio(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ copyF := func(c1 *gtsmodel.Client) *gtsmodel.Client {
+ c2 := new(gtsmodel.Client)
+ *c2 = *c1
+ return c2
+ }
+
+ c.GTS.Client.Init(structr.CacheConfig[*gtsmodel.Client]{
+ Indices: []structr.IndexConfig{
+ {Fields: "ID"},
+ },
+ MaxSize: cap,
+ IgnoreErr: ignoreErrors,
+ Copy: copyF,
+ Invalidate: c.OnInvalidateClient,
+ })
+}
+
func (c *Caches) initDomainAllow() {
c.GTS.DomainAllow = new(domain.Cache)
}
@@ -1135,7 +1168,7 @@ func (c *Caches) initTag() {
func (c *Caches) initThreadMute() {
cap := calculateResultCacheMax(
- sizeOfThreadMute(), // model in-mem size.
+ sizeofThreadMute(), // model in-mem size.
config.GetCacheThreadMuteMemRatio(),
)
@@ -1160,6 +1193,35 @@ func (c *Caches) initThreadMute() {
})
}
+func (c *Caches) initToken() {
+ // Calculate maximum cache size.
+ cap := calculateResultCacheMax(
+ sizeofToken(), // model in-mem size.
+ config.GetCacheTokenMemRatio(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ copyF := func(t1 *gtsmodel.Token) *gtsmodel.Token {
+ t2 := new(gtsmodel.Token)
+ *t2 = *t1
+ return t2
+ }
+
+ c.GTS.Token.Init(structr.CacheConfig[*gtsmodel.Token]{
+ Indices: []structr.IndexConfig{
+ {Fields: "ID"},
+ {Fields: "Code"},
+ {Fields: "Access"},
+ {Fields: "Refresh"},
+ {Fields: "ClientID", Multiple: true},
+ },
+ MaxSize: cap,
+ IgnoreErr: ignoreErrors,
+ Copy: copyF,
+ })
+}
+
func (c *Caches) initTombstone() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(