github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/cache/with_db.go (about)

     1  //go:build !no_cachedb
     2  // +build !no_cachedb
     3  
     4  package cache
     5  
     6  import (
     7  	"context"
     8  	"time"
     9  
    10  	"github.com/lmorg/murex/utils/cache/cachedb"
    11  )
    12  
    13  func SetPath(path string) {
    14  	cachedb.Path = path
    15  }
    16  
    17  func createDb(namespace string) {
    18  	cachedb.CreateTable(namespace)
    19  }
    20  
    21  func Read(namespace string, key string, ptr any) bool {
    22  	if !read(namespace, key, ptr) {
    23  		return cachedb.Read(namespace, key, ptr)
    24  	}
    25  	return true
    26  }
    27  
    28  func listDb(ctx context.Context, namespace string) (interface{}, error) {
    29  	return cachedb.List(ctx, namespace)
    30  }
    31  
    32  func Write(namespace string, key string, value any, ttl time.Time) {
    33  	write(namespace, key, value, ttl)
    34  	cachedb.Write(namespace, key, value, ttl)
    35  }
    36  
    37  func trimDb(ctx context.Context, namespace string) ([]string, error) {
    38  	return cachedb.Trim(ctx, namespace)
    39  }
    40  
    41  func flushDb(ctx context.Context, namespace string) ([]string, error) {
    42  	return cachedb.Flush(ctx, namespace)
    43  }
    44  
    45  func CloseDb() {
    46  	cachedb.CloseDb()
    47  }