summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-storage/s3/cache
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-11-10 12:36:59 +0100
committerLibravatar tobi <tobi.smethurst@protonmail.com>2025-11-17 14:13:24 +0100
commitac877bde815827f7aa1eeb3a6f0513d4c7503ad0 (patch)
tree7a315d820a5be3232dd5bfc96857017c38e906fd /vendor/codeberg.org/gruf/go-storage/s3/cache
parent[chore] update dependencies (#4542) (diff)
downloadgotosocial-ac877bde815827f7aa1eeb3a6f0513d4c7503ad0.tar.xz
[performance] add optional S3 object info caching (#4546)
This adds an optional S3 object info cache to the S3 storage driver backend (see [here](https://codeberg.org/gruf/go-storage/releases/tag/v0.4.0)) to reduce S3 calls largely during media cleanup operations, but it should also help in other situations cutting back on S3 calls when for example a key is already known to not exist. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4546 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-storage/s3/cache')
-rw-r--r--vendor/codeberg.org/gruf/go-storage/s3/cache/cache.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/codeberg.org/gruf/go-storage/s3/cache/cache.go b/vendor/codeberg.org/gruf/go-storage/s3/cache/cache.go
new file mode 100644
index 000000000..ce8aeb63b
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-storage/s3/cache/cache.go
@@ -0,0 +1,44 @@
+package cache
+
+import (
+ "time"
+
+ "codeberg.org/gruf/go-cache/v3/simple"
+ "codeberg.org/gruf/go-cache/v3/ttl"
+ "codeberg.org/gruf/go-storage/s3"
+)
+
+// check interface conformity.
+var _ s3.EntryCache = &EntryCache{}
+var _ s3.EntryCache = &EntryTTLCache{}
+
+// EntryCache provides a basic implementation
+// of an s3.EntryCache{}. Under the hood it is
+// a mutex locked ordered map with max capacity.
+type EntryCache struct {
+ simple.Cache[string, *s3.CachedObjectInfo]
+}
+
+func New(len, cap int) *EntryCache {
+ var cache EntryCache
+ cache.Init(len, cap)
+ return &cache
+}
+
+func (c *EntryCache) Put(key string, info *s3.CachedObjectInfo) {
+ c.Cache.Set(key, info)
+}
+
+type EntryTTLCache struct {
+ ttl.Cache[string, *s3.CachedObjectInfo]
+}
+
+func NewTTL(len, cap int, ttl time.Duration) *EntryTTLCache {
+ var cache EntryTTLCache
+ cache.Init(len, cap, ttl)
+ return &cache
+}
+
+func (c *EntryTTLCache) Put(key string, info *s3.CachedObjectInfo) {
+ c.Cache.Set(key, info)
+}