lrucache

package
v0.0.0-...-91649ba Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Copyright 2020 duyanghao

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Done      chan struct{}
	Completed bool
	Size      int64
}

type EvictCallback

type EvictCallback func(string)

EvictCallback is used to get a callback when a cache entry is evicted

type LruCache

type LruCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLRU

func NewLRU(size int64, onEvict EvictCallback) (*LruCache, error)

NewLRU constructs an LRU of the given size

func (*LruCache) CreateIfNotExists

func (c *LruCache) CreateIfNotExists(key string) (Entry, bool)

Create if not exists. Returns true if the entry existed.

func (*LruCache) Get

func (c *LruCache) Get(key string) (Entry, bool)

Get looks up a key's value from the cache

func (*LruCache) Output

func (c *LruCache) Output()

func (*LruCache) Remove

func (c *LruCache) Remove(key string) (present bool)

Remove removes the provided key from the cache, returning if the key was contained.

func (*LruCache) SetComplete

func (c *LruCache) SetComplete(key string, size int64) (evicted bool)

SetComplete mark completed status of cache entry. Returns true if an eviction occurred. This function only works when entry exists

Jump to

Keyboard shortcuts

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