lrucache

package module
v0.0.0-...-20a71bc Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: Apache-2.0 Imports: 3 Imported by: 30

README

LruCache Build Status Coverage Status Go Report Card

LruCache is a thread-safe, in-memory httpcache.Cache implementation that evicts the least recently used entries when a byte size limit or optional max age would be exceeded.

Using the included TwoTier wrapper, it could also be used as a small and fast cache for popular objects, falling back to a larger and slower cache (such as s3cache) for less popular ones.

Also see the godoc API documentation for LruCache or TwoTier.

Included are a test suite with close to 100% test coverage and a parallel benchmark suite that shows individual Set, Get, and Delete operations take under 400ns to complete.

License

Copyright 2016 Aaron Hopkins and contributors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Overview

Package lrucache provides a byte-size-limited implementation of httpcache.Cache that stores data in memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LruCache

type LruCache struct {
	MaxSize int64
	MaxAge  int64
	// contains filtered or unexported fields
}

LruCache is a thread-safe, in-memory httpcache.Cache that evicts the least recently used entries from memory when either MaxSize (in bytes) limit would be exceeded or (if set) the entries are older than MaxAge (in seconds). Use the New constructor to create one.

func New

func New(maxSize, maxAge int64) *LruCache

New creates an LruCache that will restrict itself to maxSize bytes of memory. If maxAge > 0, entries will also be expired after maxAge seconds.

func (*LruCache) Delete

func (c *LruCache) Delete(key string)

Delete removes the value associated with a key.

func (*LruCache) Get

func (c *LruCache) Get(key string) ([]byte, bool)

Get returns the []byte representation of a cached response and a bool set to true if the key was found.

func (*LruCache) Set

func (c *LruCache) Set(key string, value []byte)

Set stores the []byte representation of a response for a given key.

func (*LruCache) Size

func (c *LruCache) Size() int64

Size returns the estimated current memory usage of LruCache.

Directories

Path Synopsis
Package twotier provides a wrapper for two httpcache.Cache instances, allowing you to use both a small and fast cache for popular objects and fall back to a larger and slower cache for less popular ones.
Package twotier provides a wrapper for two httpcache.Cache instances, allowing you to use both a small and fast cache for popular objects and fall back to a larger and slower cache for less popular ones.

Jump to

Keyboard shortcuts

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