Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
This repository has been 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

 
 

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")
}