This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch patch/cache
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit 9b963ec73ebd05e283039b33c221c7d6585ffbf3
Author: Gao Hongtao <hanahm...@gmail.com>
AuthorDate: Mon Aug 18 23:31:39 2025 +0700

    Add bypass cache implementation for zero cache size scenarios
    
    - Introduced a new bypassCache type that implements the Cache interface as 
a no-op cache.
    - Updated PreRun methods in dataSVC and standalone to use NewBypassCache 
when MaxCacheSize is set to zero, allowing for flexible cache management.
---
 banyand/internal/storage/cache.go | 35 +++++++++++++++++++++++++++++++++++
 banyand/measure/svc_data.go       |  6 +++++-
 banyand/measure/svc_standalone.go |  6 +++++-
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/banyand/internal/storage/cache.go 
b/banyand/internal/storage/cache.go
index 2b3db287..7a890d82 100644
--- a/banyand/internal/storage/cache.go
+++ b/banyand/internal/storage/cache.go
@@ -291,3 +291,38 @@ func (sc *serviceCache) Size() uint64 {
 func (sc *serviceCache) size() uint64 {
        return atomic.LoadUint64(&sc.currentSize)
 }
+
+var _ Cache = (*bypassCache)(nil)
+
+type bypassCache struct{}
+
+// NewBypassCache creates a no-op cache implementation.
+func NewBypassCache() Cache {
+       return &bypassCache{}
+}
+
+func (bc *bypassCache) Get(_ EntryKey) Sizable {
+       return nil
+}
+
+func (bc *bypassCache) Put(_ EntryKey, _ Sizable) {
+}
+
+func (bc *bypassCache) Close() {
+}
+
+func (bc *bypassCache) Requests() uint64 {
+       return 0
+}
+
+func (bc *bypassCache) Misses() uint64 {
+       return 0
+}
+
+func (bc *bypassCache) Entries() uint64 {
+       return 0
+}
+
+func (bc *bypassCache) Size() uint64 {
+       return 0
+}
diff --git a/banyand/measure/svc_data.go b/banyand/measure/svc_data.go
index fd2ec7aa..f91bae5d 100644
--- a/banyand/measure/svc_data.go
+++ b/banyand/measure/svc_data.go
@@ -156,7 +156,11 @@ func (s *dataSVC) PreRun(ctx context.Context) error {
        if val == nil {
                return errors.New("node id is empty")
        }
-       s.c = storage.NewServiceCacheWithConfig(s.cc)
+       if s.cc.MaxCacheSize == 0 {
+               s.c = storage.NewBypassCache()
+       } else {
+               s.c = storage.NewServiceCacheWithConfig(s.cc)
+       }
        node := val.(common.Node)
        s.schemaRepo = newDataSchemaRepo(s.dataPath, s, node.Labels)
 
diff --git a/banyand/measure/svc_standalone.go 
b/banyand/measure/svc_standalone.go
index b6504730..33834bc2 100644
--- a/banyand/measure/svc_standalone.go
+++ b/banyand/measure/svc_standalone.go
@@ -161,7 +161,11 @@ func (s *standalone) PreRun(ctx context.Context) error {
        if val == nil {
                return errors.New("node id is empty")
        }
-       s.c = storage.NewServiceCacheWithConfig(s.cc)
+       if s.cc.MaxCacheSize == 0 {
+               s.c = storage.NewBypassCache()
+       } else {
+               s.c = storage.NewServiceCacheWithConfig(s.cc)
+       }
        node := val.(common.Node)
        s.schemaRepo = newSchemaRepo(s.dataPath, s, node.Labels, node.NodeID)
 

Reply via email to