twotier

package
v0.0.0-...-7e31768 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2017 License: MIT Imports: 1 Imported by: 0

README

TwoTier Build Status

TwoTier is an httpcache.Cache implementation that wraps two other httpcache.Cache instances, allowing you to use both a small and fast cache (such as an in-memory LruCache or memcache) for popular objects and fall back to a larger and slower cache (such as s3cache) for less popular ones.

While TwoTier passes Set and Delete operations to both tiers, it can't make strong guarantees that the contents of both caches will always remain in sync. If you are caching URLs that don't change often or don't mind that you sometimes get different versions of the same URL's contents, this is probably fine. When using LruCache as the first-tier cache, you can limit how long it can disagree with the second-tier cache by setting its MaxAge parameter to the maximum time you are comfortable with them disagreeing.

See the godoc API documentation for TwoTier or LruCache.

There is a test-suite included that has close to 100% test coverage on TwoTier's relatively simple functionality.

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 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TwoTier

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

TwoTier creates a two-tiered cache out of two httpcache.Cache instances. Reads are favored from first, and writes affect both first and second.

func New

func New(first httpcache.Cache, second httpcache.Cache) *TwoTier

New creates a TwoTier. Both first and second must be non-nil.

func (*TwoTier) Delete

func (c *TwoTier) Delete(key string)

Delete removes the value associated with a key from both the first and second tier caches.

func (*TwoTier) Get

func (c *TwoTier) 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. It tries the first tier cache, and if that's not successful, copies the result from the second tier into the first tier.

func (*TwoTier) Set

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

Set stores the []byte representation of a response for a given key into the second tier cache, and deletes the cache entry from the first tier cache.

Jump to

Keyboard shortcuts

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