cache

command
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 10 Imported by: 0

README

Flow 缓存示例

本文档对应当前 flow/v2/cache 包和 flow/v2/cache.NewCacheProvider() 的实现。

主要类型

  • Store
  • Driver
  • Manager
  • PrefixedManager
  • Config
  • CacheProvider

主要函数

  • RegisterDriver(name string, driver Driver)
  • GetDriver(name string)
  • New(driver string, config map[string]interface{})
  • NewManager()
  • NewCacheProvider()

Manager 主要方法

  • SetDefault
  • Register
  • GetStore
  • Store
  • Get
  • Set
  • Delete
  • Has
  • Clear
  • Increment
  • Decrement
  • GetMultiple
  • SetMultiple
  • DeleteMultiple
  • TaggedGet
  • TaggedDelete
  • WithPrefix

最小配置示例

cache:
  default: memory
  stores:
    memory:
      driver: memory
      prefix: flow:
      ttl: 5m

最小使用示例

package main

import (
    "context"
    "time"

    "github.com/zzliekkas/flow/v3/cache"
)

func main() {
    manager := cache.NewManager()
    _ = manager.Register("memory", cache.Config{
        Driver: "memory",
        TTL:    5 * time.Minute,
        Config: map[string]interface{}{},
    })
    manager.SetDefault("memory")

    _ = manager.Set(context.Background(), "hello", "world", cache.WithTags("demo"))
}

说明

  • cache 包本身提供的是抽象和管理器,不是单独的 Web 服务。
  • 具体驱动需要先通过 RegisterDriver 注册,再由 Manager 按配置创建 store。
  • CacheProvider 用于接入 app.Application,把缓存管理器注入 DI 容器。

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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