<commit_before>package cachecontrol

import (
	"github.com/labstack/echo"
	"strconv"
)

type (
	// CacheControl is a service for managing http cache-control headers
	CacheControl interface {
		Control(public, revalidate bool, maxage int) echo.MiddlewareFunc
		NoStore() echo.MiddlewareFunc
	}

	cacheControl struct {
	}
)

// New creates a new cache control service
func New() CacheControl {
	return &cacheControl{}
}

const (
	ccHeader  = "Cache-Control"
	ccPublic  = "public"
	ccPrivate = "private"
	ccNoCache = "no-cache"
	ccNoStore = "no-store"
	ccMaxAge  = "max-age"
)

// Control creates a middleware function to cache the response
func (c *cacheControl) Control(public, revalidate bool, maxage int) echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(c echo.Context) error {
			if err := next(c); err != nil {
				return err
			}

			resheader := c.Response().Header()

			if public {
				resheader.Set(ccHeader, ccPublic)
			} else {
				resheader.Set(ccHeader, ccPrivate)
			}

			if revalidate {
				resheader.Add(ccHeader, ccNoCache)
			}

			if maxage >= 0 {
				resheader.Add(ccHeader, ccMaxAge+"="+strconv.Itoa(maxage))
			}

			return nil
		}
	}
}

// NoStore creates a middleware function to deny caching responses
func (c *cacheControl) NoStore() echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(c echo.Context) error {
			if err := next(c); err != nil {
				return err
			}

			resheader := c.Response().Header()
			resheader.Set(ccHeader, ccNoStore)

			return nil
		}
	}
}

// NoStore creates a middleware function to deny caching responses
func NoStore(c CacheControl) echo.MiddlewareFunc {
	return c.NoStore()
}

// Revalidate creates a middleware function to revalidate the response on every request
func Revalidate(c CacheControl) echo.MiddlewareFunc {
	return c.Control(true, true, -1)
}<commit_msg>cache control limit methods<commit_after>package cachecontrol

import (
	"github.com/labstack/echo"
	"strconv"
)

type (
	// CacheControl is a service for managing http cache-control headers
	CacheControl interface {
		Control(public, revalidate bool, maxage int) echo.MiddlewareFunc
		NoStore() echo.MiddlewareFunc
	}

	cacheControl struct {
	}
)

// New creates a new cache control service
func New() CacheControl {
	return &cacheControl{}
}

const (
	ccHeader  = "Cache-Control"
	ccPublic  = "public"
	ccPrivate = "private"
	ccNoCache = "no-cache"
	ccNoStore = "no-store"
	ccMaxAge  = "max-age"
)

// Control creates a middleware function to cache the response
func (c *cacheControl) Control(public, revalidate bool, maxage int) echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(c echo.Context) error {
			if err := next(c); err != nil {
				return err
			}

			resheader := c.Response().Header()

			if public {
				resheader.Set(ccHeader, ccPublic)
			} else {
				resheader.Set(ccHeader, ccPrivate)
			}

			if revalidate {
				resheader.Add(ccHeader, ccNoCache)
			}

			if maxage >= 0 {
				resheader.Add(ccHeader, ccMaxAge+"="+strconv.Itoa(maxage))
			}

			return nil
		}
	}
}

// NoStore creates a middleware function to deny caching responses
func (c *cacheControl) NoStore() echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(c echo.Context) error {
			if err := next(c); err != nil {
				return err
			}

			resheader := c.Response().Header()
			resheader.Set(ccHeader, ccNoStore)

			return nil
		}
	}
}
{'fraction_non_alphanumeric': 0.108162100456621, 'fraction_numerical': 0.0008561643835616438, 'mean_word_length': 3.660904255319149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5920049', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1138, 'n_words': 318}