harbor run -t scale-ai/hil-bench-swe_38-ask_humanharbor download scale-ai/hil-bench-swe_38-ask_humanttlcache usage in an internal cache abstractionDirect use of the external ttlcache package is spread across modules, leading to duplicated cache setup code, inconsistent cache behavior, and tight coupling to an implementation detail. This makes future maintenance harder and requires type assertions when retrieving cached values.
ttlcache instance.interface{} to the expected type, increasing risk of runtime errors.ttlcache.SimpleCache[V] must exist in the utils/cache package and define methods for adding, retrieving, and listing cached values.Add(key string, value V) error must insert a value under the given key as an active cache entry with no time-based lifetime. If insertion succeeds, that value must remain retrievable through the cache until the same key is replaced by a later successful write.AddWithTTL(key string, value V, ttl time.Duration) error must insert a value using caller-provided lifetime information. For positive lifetimes, the inserted value must be retrievable while that lifetime remains active and must not remain active after that lifetime elapses.Get(key string) (V, error) must return the value associated with the key when the cache can serve it under current policy. Otherwise, it must return the zero value of V and a non-nil error.GetWithLoader(key string, loader func(key string) (V, time.Duration, error)) (V, error) must return a cached value when the cache can satisfy the request directly. Otherwise, it must consult the loader, use the loader result to satisfy the request, and update cache state according to cache lifecycle policy. If no value can be served and the loader fails, it must return the zero value of V, a non-nil error, and leave no active entry for that key. If the loader produces a value with an active lifetime but that value cannot be made active under resource policy, the call must return the zero value of V, a non-nil error, and leave existing active entries unchanged.Keys() []string must return the keys of entries that are currently active under cache policy.NewSimpleCache[V] must return an implementation of SimpleCache[V]. Values stored must be strongly typed, and retrieval must not require type assertions.New file: simple_cache.go
Path: utils/cache/simple_cache.go
Description: New file containing the generic cache interface SimpleCache[V] and its constructor NewSimpleCache[V].
Name: SimpleCache[V]
Type: interface
Path: utils/cache/simple_cache.go
Inputs:
Add(key string, value V) error
AddWithTTL(key string, value V, ttl time.Duration) error
Get(key string) (V, error)
GetWithLoader(key string, loader func(key string) (V, time.Duration, error)) (V, error)
Keys() []string
Outputs: return values as defined in each method
Description: A generic typed cache interface for insertion, lifetime-based insertion, retrieval, loader-backed retrieval, and key inspection under cache policy.
Name: NewSimpleCache[V]
Type: function
Path: utils/cache/simple_cache.go
Inputs: none
Outputs: SimpleCache[V]
Description: Constructs and returns a typed cache instance implementing the interface contract.