Skip to content
/ recache Public

Library that let's you to cache data using redis and invalidate cache by tags

License

Notifications You must be signed in to change notification settings

beono/recache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status GoDoc Go Report Card

About the project

This is an experimental library. It has a simple interface that lets you to cache data using redis and invalidate cache by tags.

If you are not familiar with invalidation by tags, then I suggest you reading this article https://symfony.com/blog/new-in-symfony-3-2-tagged-cache.

How to use

package main

import "github.com/go-redis/redis"
import "github.com/beono/recache"

func main() {

    // initialize go-redis client
    cl = redis.NewClient(&redis.Options{
        Addr: "localhost:6379",
    })

    recache = recache.NewRedisCache(cl)

    result, err := recache.Get("orders_by_user_1");
    if err == cache.ErrKeyNotFound {
        // get data from the database here
        result := getOrdersByUserID(1)

        // we can tag this cache entry.
        // if user bought iPad then we can use this tag,
        // so later we can invalidate this cache when we update ipad entity
        if err := recache.Set("orders_by_user_1", result, 3600, "orders", "ipad"); err != nil {
            t.Errorf("unexpected error: %q", err)
        }
    }

    if err != nil {
        panic(err)
    }

    fmt.Println(result)
}

About

Library that let's you to cache data using redis and invalidate cache by tags

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published