Skip to content

dmksnnk/gin-bigcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gin-bigcache

Go Report Card

An integration between Gin web framework and BigCache cache.

What

This package aims to provide an easy integration of a fast and highly-configurable cache with a quick and popular web framework to make your web service even faster.

Usage

package main

import (
    "log"
    "time"

    "github.com/allegro/bigcache/v2"
    "github.com/dmksnnk/gin-bigcache"
    "github.com/gin-gonic/gin"
    )

func main() {
    cache, err := gbcache.New(bigcache.DefaultConfig(time.Minute))
    if err != nil {
        log.Fatalf("Can't create cache!: %s", err.Error())
    }

    r := gin.Default()
    r.GET("/ping", cache.CachePage(
        func(c *gin.Context) {
            c.JSON(200, gin.H{"message": "pong"})
        }),
    )
    r.Run()
}

How

Inspired by github.com/gin-contrib/cache (which doesn't work propely with bigger responses), Gin-bigcache is a wrapper around bigcache. It stores your responses in gobs in a memory.

Package uses bigcache's config, for better tuning of your cache please refer to bigcache itself.

Releases

No releases published

Packages

No packages published

Languages