cache

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cache provides HTTP caching middleware for xun web applications. It allows setting Cache-Control headers based on configurable rules and paths.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) xun.Middleware

New creates a xun middleware that applies caching rules to HTTP responses. It accepts optional configurations through Option functions and returns a middleware that sets Cache-Control headers based on request URL paths.

Types

type Option

type Option func(o *Options)

Option is a function that configures the cache Options.

func Match

func Match(startsWith, endsWith string, duration time.Duration) Option

Match creates an Option that adds a new caching rule. The rule matches paths that start with 'startsWith' and end with 'endsWith', applying the specified cache duration.

type Options

type Options struct {
	Rules []Rule // Collection of caching rules to apply
}

Options stores configuration for the cache middleware.

type Rule

type Rule struct {
	StartsWith string        // Path prefix to match
	EndsWith   string        // Path suffix to match
	Duration   time.Duration // Cache duration to apply
}

Rule defines a caching rule with path matching criteria and cache duration. It can match request paths by prefix, suffix, or both.

func (*Rule) Match

func (r *Rule) Match(path string) bool

Match checks if the provided path matches the rule's criteria. A path matches when it satisfies both StartsWith and EndsWith conditions.

Jump to

Keyboard shortcuts

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