badgercache

package
v0.0.0-...-7e31768 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2017 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GzipMinSize gzip min size
	GzipMinSize = 1024
	// CacheFormatRaw raw
	CacheFormatRaw = 0
	// CacheFormatRawGzip raw gzip
	CacheFormatRawGzip = 1
	// CacheFormatJSON json
	CacheFormatJSON = 10
	// CacheFormatJSONGzip json gzip
	CacheFormatJSONGzip = 11
)

Variables

View Source
var (
	ErrUnknown = errors.New("unknown compression format")
	ErrEmpty   = errors.New("no data to read")
)
View Source
var (
	PluginConfig = &badgercacheConfig{
		done: make(chan struct{}),
	}
)

Config ...

Functions

func Compress

func Compress(data []byte) ([]byte, error)

func Decompress

func Decompress(data []byte) ([]byte, error)

func DetectLang

func DetectLang(content string) string

func DetectType

func DetectType(name string, content string) (string, bool)

func IsBZIP2

func IsBZIP2(b []byte) bool

func IsBZip2

func IsBZip2(r io.ReaderAt) (bool, error)

IsBZip2 checks to see if the received reader's contents are in bzip2 format by checking the magic numbers.

func IsDEB

func IsDEB(b []byte) bool

func IsGZIP

func IsGZIP(b []byte) bool

func IsGZip

func IsGZip(r io.ReaderAt) (bool, error)

IsGZip checks to see if the received reader's contents are in gzip format by checking the magic numbers.

func IsISO

func IsISO(b []byte) bool

func IsJSON

func IsJSON(b []byte) bool

func IsLZ4

func IsLZ4(r io.ReaderAt) (bool, error)

IsLZ4 checks to see if the received reader's contents are in LZ4 foramt by checking the magic numbers.

func IsLZH

func IsLZH(b []byte) bool

func IsLZMA

func IsLZMA(b []byte) bool

func IsRAR

func IsRAR(b []byte) bool

func IsTar

func IsTar(r io.ReaderAt) (bool, error)

IsTar checks to see if the received reader's contents are in the tar format by checking the magic numbers. This evaluates using both tar1 and tar2 magic numbers.

func IsXAR

func IsXAR(b []byte) bool

func IsXZ

func IsXZ(b []byte) bool

func IsYAML

func IsYAML(b []byte) bool

func IsZIP

func IsZIP(b []byte) bool

func IsZLib

func IsZLib(b []byte) bool

func IsZip

func IsZip(r io.ReaderAt) (bool, error)

IsZip checks to see if the received reader's contents are in the zip format by checking the magic numbers. This will match on zip, empty zip and spanned zip magic numbers. If you need to distinguish between those, use something else.

func Match

func Match(pattern string, in []byte) bool

func ReadHeader

func ReadHeader(content string)

func SubString

func SubString(pattern string, in []byte) bool

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache stores and retrieves data using Badger KV.

func Mount

func Mount(client *badger.DB) *Cache

func New

func New(config *Config) (*Cache, error)

func (*Cache) Action

func (c *Cache) Action(name string, args ...interface{}) (map[string]*interface{}, error)

func (*Cache) Close

func (c *Cache) Close() error

Close closes the underlying boltdb database.

func (*Cache) Debug

func (c *Cache) Debug(action string)

func (*Cache) Delete

func (c *Cache) Delete(key string)

func (*Cache) Get

func (c *Cache) Get(key string) (resp []byte, ok bool)

func (*Cache) Set

func (c *Cache) Set(key string, resp []byte)

Set stores a response to the cache at the given key.

type Check

type Check struct {
	Enabled   bool
	Key       string
	Requests  int
	CreatedAt time.Time
	UpdatedAt time.Time
	ExpiredAt time.Time
	Priority  bool
	Provider  string
}

type Config

type Config struct {
	Debug bool

	Compress bool

	// 1. Mandatory flags
	// -------------------
	// Directory to store the data in. Should exist and be writable.
	StoragePath string // Dir

	// Directory to store the value log in. Can be the same as Dir. Should
	// exist and be writable.
	ValueDir string

	// 2. Frequently modified flags
	// -----------------------------
	// Sync all writes to disk. Setting this to true would slow down data
	// loading significantly.
	SyncWrites bool

	// 3. Flags that user might want to review
	// ----------------------------------------
	// The following affect all levels of LSM tree.
	MaxTableSize        int64 // Each table (or file) is at most this size.
	LevelSizeMultiplier int   // Equals SizeOf(Li+1)/SizeOf(Li).
	MaxLevels           int   // Maximum number of levels of compaction.

	// If value size >= this threshold, only store value offsets in tree.
	ValueThreshold int

	// Maximum number of tables to keep in memory, before stalling.
	NumMemtables int

	// The following affect how we handle LSM tree L0.
	// Maximum number of Level 0 tables before we start compacting.
	NumLevelZeroTables int

	// If we hit this number of Level 0 tables, we will stall until L0 is
	// compacted away.
	NumLevelZeroTablesStall int

	// Maximum total size for L1.
	LevelOneSize int64

	// Size of single value log file.
	ValueLogFileSize int64

	// Number of compaction workers to run concurrently.
	NumCompactors int

	// 4. Flags for testing purposes
	// ------------------------------
	DoNotCompact bool // Stops LSM tree from compactions.

}

type Format

type Format int
const (
	Unknown    Format = iota // unknown format
	GZip                     // Gzip compression format
	BZip2                    // Bzip2 compression
	LZ4                      // LZ4 compression
	Tar                      // Tar format; normally used
	Tar1                     // Tar1 magicnum format; normalizes to Tar
	Tar2                     // Tar1 magicnum format; normalizes to Tar
	Zip                      // Zip archive
	ZipEmpty                 // Empty Zip Archive
	ZipSpanned               // Spanned Zip Archive
)

func GetFormat

func GetFormat(r io.ReaderAt) (Format, error)

GetFormat tries to match up the data in the Reader to a supported magic number, if a match isn't found, UnsupportedFmt is returned

For zips, this will also match on files with empty zip or spanned zip magic numbers. If you need to distinguich between the various zip formats, use something else.

func ParseFormat

func ParseFormat(s string) Format

ParseFormat takes a string and returns the format or unknown. Any compressed tar extensions are returned as the compression format and not tar.

If the passed string starts with a '.', it is removed. All strings are lowercased

func (Format) Ext

func (f Format) Ext() string

Ext returns the extension for the format. Formats may have more than one accepted extension; alternate extensiona are not supported.

func (Format) String

func (i Format) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL