Documentation
¶
Overview ¶
Package cacher implements main logic for go-apt-cacher.
Index ¶
- Variables
- func NewServer(c *Cacher, config *Config) *well.HTTPServer
- type Cacher
- type Config
- type Storage
- func (cm *Storage) Delete(p string) error
- func (cm *Storage) Insert(filename string, fi *apt.FileInfo) error
- func (cm *Storage) Len() int
- func (cm *Storage) Less(i, j int) bool
- func (cm *Storage) ListAll() []*apt.FileInfo
- func (cm *Storage) Load() error
- func (cm *Storage) Lookup(fi *apt.FileInfo) (*os.File, error)
- func (cm *Storage) Pop() interface{}
- func (cm *Storage) Push(x interface{})
- func (cm *Storage) Swap(i, j int)
- func (cm *Storage) TempFile() (*os.File, error)
- type URLMap
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned by Storage.Lookup for non-existing items. ErrNotFound = errors.New("not found") // ErrBadPath is returned by Storage.Insert if path is bad ErrBadPath = errors.New("bad path") )
var ( // ErrInvalidPrefix returned for invalid prefix. ErrInvalidPrefix = errors.New("invalid prefix") )
Functions ¶
Types ¶
type Cacher ¶
type Cacher struct {
// contains filtered or unexported fields
}
Cacher downloads and caches APT indices and deb files.
func (*Cacher) Download ¶
Download downloads an item and caches it.
If valid is not nil, the downloaded data is validated against it.
The caller receives a channel that will be closed when the item is downloaded and cached. If prefix of p is not registered in URLMap, nil is returned.
Note that download may fail, or just invalidated soon. Users of this method should retry if the item is not cached or invalidated.
type Config ¶
type Config struct { // Addr is the listening address of HTTP server. // // Default is ":3142". Addr string `toml:"listen_address"` // CheckInterval specifies interval in seconds to check updates for // Release/InRelease files. // // Default is 600 seconds. CheckInterval int `toml:"check_interval"` // CachePeriod specifies the period to cache bad HTTP response statuses. // // Default is 3 seconds. CachePeriod int `toml:"cache_period"` // MetaDirectory specifies a directory to store APT meta data files. // // This must differ from CacheDirectory. MetaDirectory string `toml:"meta_dir"` // CacheDirectory specifies a directory to cache non-meta data files. // // This must differ from MetaDirectory. CacheDirectory string `toml:"cache_dir"` // CacheCapacity specifies how many bytes can be stored in CacheDirectory. // // Unit is GiB. Default is 1 GiB. CacheCapacity int `toml:"cache_capacity"` // MaxConns specifies the maximum concurrent connections to an // upstream host. // // Zero disables limit on the number of connections. MaxConns int `toml:"max_conns"` // Log is well.LogConfig Log well.LogConfig `toml:"log"` // Mapping specifies mapping between prefixes and APT URLs. Mapping map[string]string `toml:"mapping"` }
Config is a struct to read TOML configurations.
Use https://github.com/BurntSushi/toml as follows:
config := cacher.NewConfig() md, err := toml.DecodeFile("/path/to/config.toml", config) if err != nil { ... }
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage stores cache items in local file system.
Cached items will be removed in LRU fashion when the total size of items exceeds the capacity.
func NewStorage ¶
NewStorage creates a Storage.
dir is the directory for cached items. capacity is the maximum total size (bytes) of items in the cache. If capacity is zero, items will not be evicted. Non-existing directories will be created (insufficient permission result in panic)
func (*Storage) Insert ¶
Insert inserts or updates a cache item.
fi.Path() must be as clean as filepath.Clean() and must not be filepath.IsAbs().