rclone: github.com/ncw/rclone/lib/cache Index | Files

package cache

import "github.com/ncw/rclone/lib/cache"

Package cache implements a simple cache where the entries are expired after a given time (5 minutes of disuse by default).


Package Files


type Cache Uses

type Cache struct {
    // contains filtered or unexported fields

Cache holds values indexed by string, but expired after a given (5 minutes by default).

func New Uses

func New() *Cache

New creates a new cache with the default expire duration and interval

func (*Cache) Clear Uses

func (c *Cache) Clear()

Clear removes everything from the cache

func (*Cache) Entries Uses

func (c *Cache) Entries() int

Entries returns the number of entries in the cache

func (*Cache) Get Uses

func (c *Cache) Get(key string, create CreateFunc) (value interface{}, err error)

Get gets a value named key either from the cache or creates it afresh with the create function.

func (*Cache) GetMaybe Uses

func (c *Cache) GetMaybe(key string) (value interface{}, found bool)

GetMaybe returns the key and true if found, nil and false if not

func (*Cache) Pin Uses

func (c *Cache) Pin(key string)

Pin a value in the cache if it exists

func (*Cache) Put Uses

func (c *Cache) Put(key string, value interface{})

Put puts a value named key into the cache

func (*Cache) Rename Uses

func (c *Cache) Rename(oldKey, newKey string) (value interface{}, found bool)

Rename renames the item at oldKey to newKey.

If there was an existing item at newKey then it takes precedence and is returned otherwise the item (if any) at oldKey is returned.

func (*Cache) Unpin Uses

func (c *Cache) Unpin(key string)

Unpin a value in the cache if it exists

type CreateFunc Uses

type CreateFunc func(key string) (value interface{}, ok bool, error error)

CreateFunc is called to create new values. If the create function returns an error it will be cached if ok is true, otherwise the error will just be returned, allowing negative caching if required.

Package cache imports 2 packages (graph). Updated 2020-08-05. Refresh now. Tools for package owners.