Introduce cache package
- Dominant language
- Go
- Stars
- 12
- Forks
- 34
- Avg merge
- 1h 11m
- Merged PRs (30d)
- 1
Description
**Is your feature request related to a problem? Please describe.**
Several components across the KubeVela ecosystem need a simple in-memory cache with per-entry TTL (e.g., helm index files, chart objects, OCI registry responses). Currently, a `MemoryCacheStore` implementation lives in `kubevela/kubevela/pkg/utils/cache.go`, but it is:
1. **Not reusable outside kubevela/kubevela** — other repos (apis, controller, etc.) must import the entire kubevela module to use an cache utility.
2. **Tightly coupled to a concrete type** — consumers declare fields as `*MemoryCacheStore`, not an interface. Switching from sync.Map to a bounded LRU (needed for large helm chart objects) would require changes at every call site.
3. **No abstraction for alternate backends** — there is no interface contract, so a Redis-backed or LRU-backed cache would be an entirely separate implementation with no common ground, forcing consumers to write conditional branching per backend type.
**Describe the solution you'd like**
Extract the cache into this repo as a self-contained, zero-dependency Go package with:
- A `Cache` interface defining `Put`, `Get`, and `Delete` — consumers depend on this interface, not on concrete types.
- A `MemoryCache` implementation backed by `sync.Map` with per-entry TTL and a background eviction goroutine migrated identically from `kubevela/kubevela/pkg/utils/cache.go`.
- The interface must remain minimal. Each constructor is responsible for its own lifecycle.
**Additional context**
This is the first extraction under the "centralize shared utilities in
kubevela/pkg" initiative. Future phases will add:
- `LRUCache` (hashicorp/golang-lru backed) with bounded size for chart objects — addresses the memory pressure problem in the helm provider where full `*chart.Chart` objects (megabytes each) accumulate without limit in the current sync.Map.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading kubevela/kubevela/pkg/utils/cache.go and tracing the existing MemoryCacheStore behavior, including TTL handling and background eviction. Then review the requested Cache methods and the kubevela/pkg package structure before deciding how the extracted package should expose its implementation. Done means a self-contained Go package provides the requested interface and equivalent in-memory behavior without importing the full kubevela module.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100