Skip to content
This repository was archived by the owner on May 3, 2023. It is now read-only.
/ cache Public archive
forked from gin-contrib/cache

Gin middleware/handler to enable Cache

License

Notifications You must be signed in to change notification settings

Bose/cache

This branch is 40 commits ahead of, 53 commits behind gin-contrib/cache:master.

Folders and files

NameName
Last commit message
Last commit date
Aug 11, 2020
Aug 12, 2020
Nov 14, 2016
Aug 11, 2020
Sep 7, 2019
Aug 7, 2020
Aug 7, 2020
May 3, 2023
Aug 11, 2020
Aug 11, 2020
Aug 11, 2020
May 28, 2019

Repository files navigation

Cache gin's middleware - ARCHIVED

This repository has been forked to BoseCorp/cache-lib private repository.

Go Report Card GoDoc

Gin middleware/handler to enable Cache.

Please see CODE_OF_CONDUCT for contribution guidelines.

Usage

Start using it

Download and install it:

$ go get github.com/Bose/cache

Import it in your code:

import "github.com/Bose/cache"

Canonical example:

See the example

package main

import (
	"fmt"
	"time"

	"github.com/Bose/cache"
	"github.com/Bose/cache/persistence"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()

	store := persistence.NewInMemoryStore(time.Second)
	
	r.GET("/ping", func(c *gin.Context) {
		c.String(200, "pong "+fmt.Sprint(time.Now().Unix()))
	})
	// Cached Page
	r.GET("/cache_ping", cache.CachePage(store, time.Minute, func(c *gin.Context) {
		c.String(200, "pong "+fmt.Sprint(time.Now().Unix()))
	}))

	// Listen and Server in 0.0.0.0:8080
	r.Run(":8080")
}