cache

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRoutes

func RegisterRoutes(e *echo.Group, h *Handler, authMiddleware *auth.Middleware)

RegisterRoutes registers cache management routes on the given echo instance. GET /cache requires config:read; POST /cache/:id/clear requires config:write.

func RegisterSettingsRoutes added in v0.2.0

func RegisterSettingsRoutes(e *echo.Group, authMiddleware *auth.Middleware, store *appsettings.Service, caches Limiters)

RegisterSettingsRoutes registers persisted policy alongside other admin settings.

Types

type ClearResponse

type ClearResponse struct {
	ClearedBytes int64 `json:"cleared_bytes"`
	ClearedFiles int   `json:"cleared_files"`
}

ClearResponse is returned from POST /cache/:id/clear.

type Handler

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

Handler exposes HTTP endpoints for cache management.

func NewHandler

func NewHandler(downloads, cbzPages, pdfPages, coverThumbnails Provider) *Handler

NewHandler returns a new cache management handler.

type Info

type Info struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	SizeBytes   int64  `json:"size_bytes"`
	FileCount   int    `json:"file_count"`
}

Info describes one cache. GET /cache returns a bare array of them. The type name avoids stuttering (cache.Info instead of cache.CacheInfo).

type Limit added in v0.3.0

type Limit struct {
	// MaxSizeGB is kept while Unlimited is set, so lifting the limit and
	// restoring it later brings back the same size.
	MaxSizeGB float64 `json:"max_size_gb"`
	Unlimited bool    `json:"unlimited"`
}

Limit is one cache's disk budget.

func (Limit) Bytes added in v0.3.0

func (l Limit) Bytes() int64

Bytes returns the budget a cache enforces: math.MaxInt64 when unlimited, which no cache can exceed.

type LimitPayload added in v0.3.0

type LimitPayload struct {
	MaxSizeGB *float64 `json:"max_size_gb" validate:"required,min=0,max=1024" tstype:"number,required"`
	Unlimited *bool    `json:"unlimited" validate:"required" tstype:"boolean,required"`
}

LimitPayload sets one cache's limit. Both fields are required, so a client that leaves out the size cannot empty the cache by reading it as 0.

type Limiter added in v0.3.0

type Limiter interface {
	SetMaxBytes(maxBytes int64) error
}

Limiter is a cache whose disk budget can change while the server runs.

type Limiters added in v0.3.0

type Limiters struct {
	CoverThumbnails Limiter
	Downloads       Limiter
	CBZPages        Limiter
	PDFPages        Limiter
}

Limiters are the caches the settings control, one per settings field. A nil limiter is skipped.

func (Limiters) Apply added in v0.3.0

func (l Limiters) Apply(s SettingsResponse, ids ...string) error

Apply sets each named cache's limit from s, or every cache's when no id is given. It applies them all even when one fails and returns the failures together, so one cache that cannot be cleaned does not leave the others on their old limits.

type Provider

type Provider interface {
	SizeBytes() (int64, int, error)
	Clear() error
}

Provider is the minimal interface a cache must implement to be managed.

type SettingsResponse added in v0.2.0

type SettingsResponse struct {
	CoverThumbnails Limit `json:"cover_thumbnails"`
	Downloads       Limit `json:"downloads"`
	CBZPages        Limit `json:"cbz_pages"`
	PDFPages        Limit `json:"pdf_pages"`
}

SettingsResponse contains the admin-editable cache policy. Each field is named after the id of its cache in GET /cache.

func LoadSettings added in v0.2.0

func LoadSettings(ctx context.Context, store *appsettings.Service) (SettingsResponse, error)

LoadSettings reads saved policy without persisting defaults on a GET.

type UpdateSettingsPayload added in v0.2.0

type UpdateSettingsPayload struct {
	CoverThumbnails *LimitPayload `json:"cover_thumbnails,omitempty"`
	Downloads       *LimitPayload `json:"downloads,omitempty"`
	CBZPages        *LimitPayload `json:"cbz_pages,omitempty"`
	PDFPages        *LimitPayload `json:"pdf_pages,omitempty"`
}

UpdateSettingsPayload changes the limits it names and leaves the rest.

Jump to

Keyboard shortcuts

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