gbcache

package module
v0.0.0-...-f9206b7 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2020 License: MIT Imports: 7 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache stores reference to a storage

func New

func New(cfg bigcache.Config) (*Cache, error)

New creates new cache with given bigcache config

func (*Cache) CachePage

func (cache *Cache) CachePage(handle gin.HandlerFunc) gin.HandlerFunc

CachePage caches response from gin handler function

func (*Cache) CachePageWithoutHeader

func (cache *Cache) CachePageWithoutHeader(handle gin.HandlerFunc) gin.HandlerFunc

CachePageWithoutHeader returns a page from cache without headers

func (*Cache) CachePageWithoutQuery

func (cache *Cache) CachePageWithoutQuery(handle gin.HandlerFunc) gin.HandlerFunc

CachePageWithoutQuery adds ability to ignore GET query parameters

Jump to

Keyboard shortcuts

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