Remove cache fields from Server struct (bd-31)

- Removed storageCache, cacheMu, maxCacheSize, cacheTTL, cleanupTicker fields
- Removed cacheHits and cacheMisses metrics
- Removed cache size/TTL parsing from env vars in NewServer()
- Removed cleanup ticker goroutine from Start()
- Removed cache cleanup logic from Stop()
- Part of bd-29 epic to remove daemon storage cache

Amp-Thread-ID: https://ampcode.com/threads/T-239a5531-68a5-4c98-b85d-0e3512b2553c
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-27 23:20:06 -07:00
parent c7477464fc
commit 9edcb6f19f
2 changed files with 1 additions and 45 deletions

View File

@@ -32,17 +32,9 @@ type Server struct {
shutdownChan chan struct{}
stopOnce sync.Once
doneChan chan struct{} // closed when Start() cleanup is complete
// Per-request storage routing with eviction support
storageCache map[string]*StorageCacheEntry // repoRoot -> entry
cacheMu sync.RWMutex
maxCacheSize int
cacheTTL time.Duration
cleanupTicker *time.Ticker
// Health and metrics
startTime time.Time
lastActivityTime atomic.Value // time.Time - last request timestamp
cacheHits int64
cacheMisses int64
metrics *Metrics
// Connection limiting
maxConns int
@@ -59,22 +51,6 @@ type Server struct {
// NewServer creates a new RPC server
func NewServer(socketPath string, store storage.Storage, workspacePath string, dbPath string) *Server {
// Parse config from env vars
maxCacheSize := 50 // default
if env := os.Getenv("BEADS_DAEMON_MAX_CACHE_SIZE"); env != "" {
// Parse as integer
var size int
if _, err := fmt.Sscanf(env, "%d", &size); err == nil && size > 0 {
maxCacheSize = size
}
}
cacheTTL := 30 * time.Minute // default
if env := os.Getenv("BEADS_DAEMON_CACHE_TTL"); env != "" {
if ttl, err := time.ParseDuration(env); err == nil && ttl > 0 {
cacheTTL = ttl
}
}
maxConns := 100 // default
if env := os.Getenv("BEADS_DAEMON_MAX_CONNS"); env != "" {
var conns int
@@ -95,9 +71,6 @@ func NewServer(socketPath string, store storage.Storage, workspacePath string, d
workspacePath: workspacePath,
dbPath: dbPath,
storage: store,
storageCache: make(map[string]*StorageCacheEntry),
maxCacheSize: maxCacheSize,
cacheTTL: cacheTTL,
shutdownChan: make(chan struct{}),
doneChan: make(chan struct{}),
startTime: time.Now(),

View File

@@ -49,7 +49,6 @@ func (s *Server) Start(_ context.Context) error {
close(s.readyChan)
go s.handleSignals()
go s.runCleanupLoop()
// Ensure cleanup is signaled when this function returns
defer close(s.doneChan)
@@ -107,23 +106,7 @@ func (s *Server) Stop() error {
// Signal cleanup goroutine to stop
close(s.shutdownChan)
// Close all cached storage connections outside lock
s.cacheMu.Lock()
stores := make([]storage.Storage, 0, len(s.storageCache))
for _, entry := range s.storageCache {
stores = append(stores, entry.store)
}
s.storageCache = make(map[string]*StorageCacheEntry)
s.cacheMu.Unlock()
// Close stores without holding lock
for _, store := range stores {
if closeErr := store.Close(); closeErr != nil {
fmt.Fprintf(os.Stderr, "Warning: failed to close storage: %v\n", closeErr)
}
}
// Close default storage
// Close storage
if s.storage != nil {
if closeErr := s.storage.Close(); closeErr != nil {
fmt.Fprintf(os.Stderr, "Warning: failed to close default storage: %v\n", closeErr)