Documentation ¶
Overview ¶
Package cache implements RDAP Service Registry file caching.
There are two separate implementations: MemoryCache and DiskCache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiskCache ¶
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 (*DiskCache) InitDir ¶
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 ¶
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 ¶
Save saves the file |filename| with |data| to disk.
The cache directory is created if necessary.
func (*DiskCache) SetTimeout ¶
SetTimeout sets the duration each Service Registry file can be stored before its State() is Expired.
type FileState ¶
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 )
type MemoryCache ¶
A MemoryCache caches Service Registry files in memory.
func (*MemoryCache) Load ¶
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 ¶
func (m *MemoryCache) Save(filename string, data []byte) error
Save saves the file |filename| with |data| to the cache.
func (*MemoryCache) SetTimeout ¶
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 ¶
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.