File: registry_cache.go

package info (click to toggle)
rdap 0.9.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 608 kB
  • sloc: makefile: 4
file content (51 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// OpenRDAP
// Copyright 2017 Tom Harwood
// MIT License, see the LICENSE file.

// Package cache implements RDAP Service Registry file caching.
//
// There are two separate implementations: MemoryCache and DiskCache.
package cache

import "time"

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 (f FileState) String() string {
	switch f {
	case Absent:
		return "not cached"
	case Good, ShouldReload:
		return "good"
	case Expired:
		return "expired"
	default:
		panic("Unknown FileState")
	}
}

// A RegistryCache implements a cache of Service Registry files.
type RegistryCache interface {
	Load(filename string) ([]byte, error)
	Save(filename string, data []byte) error

	State(filename string) FileState

	SetTimeout(timeout time.Duration)
}