Skip to content

things-kit/things-kit-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Things-Kit Cache

Cache Interface Abstraction for Things-Kit

This module defines the cache abstraction for Things-Kit applications. It contains only interfaces, no implementation.

Installation

go get github.com/things-kit/things-kit-cache

Purpose

The things-kit-cache package defines the contract that all cache implementations must follow. This allows applications to program against a stable interface while being free to choose any cache backend (Redis, Valkey, Memcached, in-memory, etc.).

Interfaces

Cache

The Cache interface defines operations for a distributed key-value cache:

type Cache interface {
    // Basic operations
    Get(ctx context.Context, key string) (string, error)
    Set(ctx context.Context, key string, value string, expiration time.Duration) error
    Delete(ctx context.Context, key string) error
    Exists(ctx context.Context, key string) (bool, error)
    
    // Binary data operations
    GetBytes(ctx context.Context, key string) ([]byte, error)
    SetBytes(ctx context.Context, key string, value []byte, expiration time.Duration) error
    
    // Expiration management
    Expire(ctx context.Context, key string, expiration time.Duration) (bool, error)
    TTL(ctx context.Context, key string) (time.Duration, error)
    
    // Connection management
    Ping(ctx context.Context) error
    Close() error
}

BatchCache

The BatchCache interface extends Cache with batch operations for improved performance:

type BatchCache interface {
    Cache
    
    MGet(ctx context.Context, keys ...string) (map[string]string, error)
    MSet(ctx context.Context, pairs map[string]string, expiration time.Duration) error
    MDelete(ctx context.Context, keys ...string) error
}

Available Implementations

things-kit-redis (Recommended)

The things-kit-redis module provides a Redis-based implementation.

import (
    "github.com/things-kit/things-kit/app"
    "github.com/things-kit/things-kit-cache"
    "github.com/things-kit/things-kit-redis"
)

func main() {
    app.New(
        viperconfig.Module,
        logging.Module,
        redis.Module,  // Provides cache.Cache
        
        fx.Provide(NewMyService),
    ).Run()
}

License

MIT License - see LICENSE file for details

About

Things-Kit Cache Interface - Cache abstraction for Go applications

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages