diff --git a/automod/cachestore/cachestore.go b/automod/cachestore/cachestore.go new file mode 100644 index 000000000..593364403 --- /dev/null +++ b/automod/cachestore/cachestore.go @@ -0,0 +1,11 @@ +package cachestore + +import ( + "context" +) + +type CacheStore interface { + Get(ctx context.Context, name, key string) (string, error) + Set(ctx context.Context, name, key string, val string) error + Purge(ctx context.Context, name, key string) error +} diff --git a/automod/cachestore.go b/automod/cachestore/cachestore_mem.go similarity index 76% rename from automod/cachestore.go rename to automod/cachestore/cachestore_mem.go index 2c7c855ec..3592554e3 100644 --- a/automod/cachestore.go +++ b/automod/cachestore/cachestore_mem.go @@ -1,4 +1,4 @@ -package automod +package cachestore import ( "context" @@ -7,12 +7,6 @@ import ( "github.com/hashicorp/golang-lru/v2/expirable" ) -type CacheStore interface { - Get(ctx context.Context, name, key string) (string, error) - Set(ctx context.Context, name, key string, val string) error - Purge(ctx context.Context, name, key string) error -} - type MemCacheStore struct { Data *expirable.LRU[string, string] } diff --git a/automod/redis_cache.go b/automod/cachestore/cachestore_redis.go similarity index 98% rename from automod/redis_cache.go rename to automod/cachestore/cachestore_redis.go index f057ff11f..26b1aacbb 100644 --- a/automod/redis_cache.go +++ b/automod/cachestore/cachestore_redis.go @@ -1,4 +1,4 @@ -package automod +package cachestore import ( "context" diff --git a/automod/engine.go b/automod/engine.go index 4b76548e5..b612e93bc 100644 --- a/automod/engine.go +++ b/automod/engine.go @@ -8,6 +8,7 @@ import ( "github.com/bluesky-social/indigo/atproto/identity" "github.com/bluesky-social/indigo/atproto/syntax" + "github.com/bluesky-social/indigo/automod/cachestore" "github.com/bluesky-social/indigo/automod/countstore" "github.com/bluesky-social/indigo/automod/flagstore" "github.com/bluesky-social/indigo/xrpc" @@ -22,7 +23,7 @@ type Engine struct { Rules RuleSet Counters countstore.CountStore Sets SetStore - Cache CacheStore + Cache cachestore.CacheStore Flags flagstore.FlagStore RelayClient *xrpc.Client BskyClient *xrpc.Client diff --git a/automod/testing.go b/automod/testing.go index 6551e46ce..901655072 100644 --- a/automod/testing.go +++ b/automod/testing.go @@ -11,6 +11,7 @@ import ( appbsky "github.com/bluesky-social/indigo/api/bsky" "github.com/bluesky-social/indigo/atproto/identity" "github.com/bluesky-social/indigo/atproto/syntax" + "github.com/bluesky-social/indigo/automod/cachestore" "github.com/bluesky-social/indigo/automod/countstore" "github.com/bluesky-social/indigo/automod/flagstore" ) @@ -42,7 +43,7 @@ func EngineTestFixture() Engine { simpleRule, }, } - cache := NewMemCacheStore(10, time.Hour) + cache := cachestore.NewMemCacheStore(10, time.Hour) flags := flagstore.NewMemFlagStore() sets := NewMemSetStore() sets.Sets["bad-hashtags"] = make(map[string]bool) diff --git a/cmd/hepa/server.go b/cmd/hepa/server.go index dbab7058e..fbd88a04c 100644 --- a/cmd/hepa/server.go +++ b/cmd/hepa/server.go @@ -12,6 +12,7 @@ import ( comatproto "github.com/bluesky-social/indigo/api/atproto" "github.com/bluesky-social/indigo/atproto/identity" "github.com/bluesky-social/indigo/automod" + "github.com/bluesky-social/indigo/automod/cachestore" "github.com/bluesky-social/indigo/automod/countstore" "github.com/bluesky-social/indigo/automod/flagstore" "github.com/bluesky-social/indigo/automod/rules" @@ -89,7 +90,7 @@ func NewServer(dir identity.Directory, config Config) (*Server, error) { } var counters countstore.CountStore - var cache automod.CacheStore + var cache cachestore.CacheStore var flags flagstore.FlagStore var rdb *redis.Client if config.RedisURL != "" { @@ -111,7 +112,7 @@ func NewServer(dir identity.Directory, config Config) (*Server, error) { } counters = cnt - csh, err := automod.NewRedisCacheStore(config.RedisURL, 30*time.Minute) + csh, err := cachestore.NewRedisCacheStore(config.RedisURL, 30*time.Minute) if err != nil { return nil, fmt.Errorf("initializing redis cachestore: %v", err) } @@ -124,7 +125,7 @@ func NewServer(dir identity.Directory, config Config) (*Server, error) { flags = flg } else { counters = countstore.NewMemCountStore() - cache = automod.NewMemCacheStore(5_000, 30*time.Minute) + cache = cachestore.NewMemCacheStore(5_000, 30*time.Minute) flags = flagstore.NewMemFlagStore() }