libpack_cache

package
v0.34.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheClear added in v0.18.7

func CacheClear()

func CacheDelete added in v0.18.7

func CacheDelete(hash string)

func CacheGetQueries added in v0.18.7

func CacheGetQueries() int64

func CacheLookup added in v0.18.7

func CacheLookup(hash string) []byte

func CacheStore added in v0.18.7

func CacheStore(hash string, data []byte)

func CacheStoreWithTTL added in v0.18.7

func CacheStoreWithTTL(hash string, data []byte, ttl time.Duration)

func CalculateHash added in v0.18.7

func CalculateHash(c *fiber.Ctx) string

CalculateHash generates an MD5 hash from the request body. For GraphQL requests, this includes both the query and variables, ensuring that identical queries with different variables are cached separately.

Example GraphQL request body:

{
  "query": "query GetUser($id: ID!) { user(id: $id) { name } }",
  "variables": { "id": "123" }
}

Different variable values will produce different cache keys.

func EnableCache added in v0.18.7

func EnableCache(cfg *CacheConfig)

func GetCacheMaxMemorySize added in v0.29.1

func GetCacheMaxMemorySize() int64

GetCacheMaxMemorySize returns the maximum memory size allowed for the cache in bytes

func GetCacheMemoryUsage added in v0.29.1

func GetCacheMemoryUsage() int64

GetCacheMemoryUsage returns the current memory usage of the cache in bytes

func IsCacheInitialized added in v0.21.82

func IsCacheInitialized() bool

func ShouldUseRedisCache added in v0.18.7

func ShouldUseRedisCache(cfg *CacheConfig) bool

Types

type CacheClient added in v0.18.7

type CacheClient interface {
	Set(key string, value []byte, ttl time.Duration)
	Get(key string) ([]byte, bool)
	Delete(key string)
	Clear()
	CountQueries() int64
	// Memory usage reporting methods
	GetMemoryUsage() int64   // Returns current memory usage in bytes
	GetMaxMemorySize() int64 // Returns max memory size in bytes
}

type CacheConfig added in v0.18.7

type CacheConfig struct {
	Logger *libpack_logger.Logger
	Client CacheClient
	Redis  struct {
		URL      string `json:"url"`
		Password string `json:"password"`
		DB       int    `json:"db"`
		Enable   bool   `json:"enable"`
	}
	Memory struct {
		MaxMemorySize int64 `json:"max_memory_size"` // Maximum memory size in bytes
		MaxEntries    int64 `json:"max_entries"`     // Maximum number of entries
	}
	TTL int `json:"ttl"`
}

type CacheStats added in v0.15.4

type CacheStats struct {
	CachedQueries int64 `json:"cached_queries"`
	CacheHits     int64 `json:"cache_hits"`
	CacheMisses   int64 `json:"cache_misses"`
}

func GetCacheStats added in v0.18.7

func GetCacheStats() *CacheStats

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL