rdap: github.com/openrdap/rdap/bootstrap/cache Index | Files

package cache

import "github.com/openrdap/rdap/bootstrap/cache"

Package cache implements RDAP Service Registry file caching.

There are two separate implementations: MemoryCache and DiskCache.

Index

Package Files

disk_cache.go memory_cache.go registry_cache.go

type DiskCache Uses

type DiskCache struct {
    // Duration files are stored before they're considered expired.
    //
    // The default is 24 hours.
    Timeout time.Duration

    // Directory to store cached files in.
    //
    // The default is $HOME/.openrdap.
    Dir string
    // contains filtered or unexported fields
}

A DiskCache caches Service Registry files on disk.

By default they're saved as $HOME/.openrdap/{asn,dns,ipv4,ipv6}.json. File mtimes are used to calculate cache expiry.

The cache directory is created automatically as needed.

func NewDiskCache Uses

func NewDiskCache() *DiskCache

NewDiskCache creates a new DiskCache.

func (*DiskCache) InitDir Uses

func (d *DiskCache) InitDir() (bool, error)

InitDir creates the cache directory if it does not already exist.

Returns true if the directory was created, or false if it already exists/or on error.

func (*DiskCache) Load Uses

func (d *DiskCache) Load(filename string) ([]byte, error)

Load loads the file |filename| from disk.

Since Service Registry files do not change much, the file is returned even if its State() is Expired.

An error is returned if the file is not on disk.

func (*DiskCache) Save Uses

func (d *DiskCache) Save(filename string, data []byte) error

Save saves the file |filename| with |data| to disk.

The cache directory is created if necessary.

func (*DiskCache) SetTimeout Uses

func (d *DiskCache) SetTimeout(timeout time.Duration)

SetTimeout sets the duration each Service Registry file can be stored before its State() is Expired.

func (*DiskCache) State Uses

func (d *DiskCache) State(filename string) FileState

State returns the cache state of the file |filename|.

The returned state is one of: Absent, Good, ShouldReload, Expired.

type FileState Uses

type FileState int
const (
    // File is not in the cache.
    Absent FileState = iota

    // File is in the cache. The latest version has already accessed (Load or Saved()).
    Good

    // File is in the cache. A newer version of is available to be Load()'ed.
    //
    // This is used by DiskCache, which uses a shared cache directory.
    ShouldReload

    // File is in the cache, but has expired. It still can be Load()'ed.
    Expired
)

func (FileState) String Uses

func (f FileState) String() string

type MemoryCache Uses

type MemoryCache struct {
    Timeout time.Duration
    // contains filtered or unexported fields
}

A MemoryCache caches Service Registry files in memory.

func NewMemoryCache Uses

func NewMemoryCache() *MemoryCache

NewMemoryCache creates a new MemoryCache.

func (*MemoryCache) Load Uses

func (m *MemoryCache) Load(filename string) ([]byte, error)

Load returns the file |filename| from the cache.

Since Service Registry files do not change much, the file is returned even if its State() is Expired.

An error is returned if the file is not in the cache.

func (*MemoryCache) Save Uses

func (m *MemoryCache) Save(filename string, data []byte) error

Save saves the file |filename| with |data| to the cache.

func (*MemoryCache) SetTimeout Uses

func (m *MemoryCache) SetTimeout(timeout time.Duration)

SetTimeout sets the duration each Service Registry file can be stored before its State() is Expired.

func (*MemoryCache) State Uses

func (m *MemoryCache) State(filename string) FileState

State returns the cache state of the file |filename|.

The returned state is one of: Absent, Good, Expired.

type RegistryCache Uses

type RegistryCache interface {
    Load(filename string) ([]byte, error)
    Save(filename string, data []byte) error

    State(filename string) FileState

    SetTimeout(timeout time.Duration)
}

A RegistryCache implements a cache of Service Registry files.

Package cache imports 7 packages (graph) and is imported by 2 packages. Updated 2018-02-23. Refresh now. Tools for package owners.