cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Copyright 2024 Blnk Finance Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Set stores a value in the cache with a specified time-to-live (TTL).
	// Parameters:
	// - ctx: The context for managing the request lifecycle.
	// - key: The cache key under which the value will be stored.
	// - value: The value to be stored in the cache.
	// - ttl: The duration the value should be retained in the cache.
	// Returns an error if the operation fails.
	Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error

	// Get retrieves a value from the cache using a given key.
	// Parameters:
	// - ctx: The context for managing the request lifecycle.
	// - key: The cache key to fetch the value.
	// - data: The variable to store the fetched data.
	// Returns an error if the key does not exist or retrieval fails.
	Get(ctx context.Context, key string, data interface{}) error

	// Delete removes a value from the cache based on the provided key.
	// Parameters:
	// - ctx: The context for managing the request lifecycle.
	// - key: The cache key to be deleted.
	// Returns an error if the key cannot be deleted.
	Delete(ctx context.Context, key string) error
}

Cache interface provides the basic operations for a cache system. It includes methods for setting, getting, and deleting cached data.

func NewCache

func NewCache() (Cache, error)

NewCache creates a new instance of RedisCache by establishing a connection to Redis. It fetches the configuration, initializes Redis, and returns a Cache instance. Returns an error if the configuration or Redis initialization fails.

func NewCacheWithClient

func NewCacheWithClient(client redis.UniversalClient) Cache

NewCacheWithClient creates a new RedisCache using an existing Redis client. No error is returned because no I/O occurs — the client is already validated.

type RedisCache

type RedisCache struct {
	// contains filtered or unexported fields
}

RedisCache implements the Cache interface, using Redis as the underlying cache store. It leverages both Redis and local in-memory caching for efficient lookups.

func (*RedisCache) Delete

func (r *RedisCache) Delete(ctx context.Context, key string) error

Delete removes an entry from the cache based on the provided key. Parameters: - ctx: The context for the operation. - key: The cache key to delete. Returns an error if the deletion fails.

func (*RedisCache) Get

func (r *RedisCache) Get(ctx context.Context, key string, data interface{}) error

Get retrieves an entry from the cache based on the provided key. Parameters: - ctx: The context for the operation. - key: The cache key to retrieve. - data: The variable to store the retrieved data. Returns an error if the key does not exist or if the retrieval fails.

func (*RedisCache) Set

func (r *RedisCache) Set(ctx context.Context, key string, data interface{}, ttl time.Duration) error

Set adds a new entry to the cache with a specified key and TTL. Parameters: - ctx: The context for the operation. - key: The cache key under which to store the value. - data: The value to be cached. - ttl: The time-to-live duration for the cached value. Returns an error if the caching operation fails.

Jump to

Keyboard shortcuts

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