mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-01 14:46:36 +08:00
refactor(oauth): replace legacy oauth cache with standard ram cache and add pubsub synchronization
- Replaced custom map-based cache in apps/oauth/cache.go with standard pkg/cache/ram framework. - Implemented Redis Pub/Sub invalidation channels for distributed token and user cache synchronization. - Created apps/oauth/cache_test.go to verify local cache operations and pub/sub broadcasts. refactor(cache): generic RAM cache with CoW and unified preheating Replaced L2 Redis cache and old cache package with process-local generic pkg/cache/ram. Implemented Copy-on-Write for reads, fine-grained locks per type for writes, and unified preheating in bootstrap. Changed cache invalidation to lazy-loading to resolve SQLite deadlocks during transactions.
This commit is contained in:
@@ -36,6 +36,11 @@ func SetupTestEnvironment(t *testing.T) (*gorm.DB, *miniredis.Miniredis, func())
|
||||
t.Fatalf("failed to open in-memory SQLite db: %v", err)
|
||||
}
|
||||
|
||||
// Limit to 1 open connection for SQLite :memory: to keep the database in one shared connection
|
||||
if sqlDB, err := sqliteDB.DB(); err == nil {
|
||||
sqlDB.SetMaxOpenConns(1)
|
||||
}
|
||||
|
||||
// AutoMigrate all tables
|
||||
err = sqliteDB.AutoMigrate(
|
||||
&model.User{},
|
||||
@@ -77,6 +82,8 @@ func SetupTestEnvironment(t *testing.T) (*gorm.DB, *miniredis.Miniredis, func())
|
||||
// Cleanup function
|
||||
cleanup := func() {
|
||||
runExtraCleanups()
|
||||
repository.StopSystemConfigCacheListener()
|
||||
repository.StopAuthSourceCacheListener()
|
||||
repository.ResetSystemConfigRAMCacheForTest()
|
||||
_ = redisClient.Close()
|
||||
mr.Close()
|
||||
|
||||
Reference in New Issue
Block a user