cache

package
v0.0.0-...-76bf06a Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2019 License: MIT Imports: 18 Imported by: 1

README

Autocert/cache

autocert.Cache implementations Allow the use of precaching for realy fast reads and encryption for better security.

Configuration

Dir Cache backend

Simply wraps golang.org/x/crypto/acme/autocert.DirCache

Required options:

  • path - path to the directory to store cache. Directory may exist or will be created automatically.

Redis Cache backend

Redis cache

Required options:

  • addr - Redis database address

Additional options:

  • password - database password
  • db - database (0 - for default database)

SQL Cache backend

Backend allows to use relational database as a storage.

Required options:

  • driver - database driver to use. Allowed options: mysql, postgres

  • dsn - Data source name refering database in the form supported by Go's drivers. Examples:

    • MySQL: root@tcp(127.0.0.1:3306)/db_name?parseTime=true
    • PostgreSQL: postgres://postgres@localhost/db_name?sslmode=disable

    More examples can be found in tests.

Benchmarks

› make benchmark
go test -bench=. -cpu=1,2,3,4
goos: darwin
goarch: amd64
pkg: jgocache/autocert/cache
BenchmarkCacheGetSQLMySQLWithoutEncryptionAndPrecaching              	    2000	    916999 ns/op
BenchmarkCacheGetSQLMySQLWithoutEncryptionAndPrecaching-2            	    2000	    930788 ns/op
BenchmarkCacheGetSQLMySQLWithoutEncryptionAndPrecaching-3            	    2000	    926944 ns/op
BenchmarkCacheGetSQLMySQLWithoutEncryptionAndPrecaching-4            	    2000	    928512 ns/op
BenchmarkCacheGetSQLMySQLWithEncryptionAndWithoutPrecaching          	    2000	    927463 ns/op
BenchmarkCacheGetSQLMySQLWithEncryptionAndWithoutPrecaching-2        	    2000	    944562 ns/op
BenchmarkCacheGetSQLMySQLWithEncryptionAndWithoutPrecaching-3        	    2000	    942038 ns/op
BenchmarkCacheGetSQLMySQLWithEncryptionAndWithoutPrecaching-4        	    2000	    943408 ns/op
BenchmarkCacheGetSQLMySQLWithEncryptionAndPrecaching                 	30000000	        39.0 ns/op
BenchmarkCacheGetSQLMySQLWithEncryptionAndPrecaching-2               	30000000	        38.0 ns/op
BenchmarkCacheGetSQLMySQLWithEncryptionAndPrecaching-3               	30000000	        38.4 ns/op
BenchmarkCacheGetSQLMySQLWithEncryptionAndPrecaching-4               	30000000	        37.9 ns/op
BenchmarkCacheGetSQLPostgreSQLWithoutEncryptionAndPrecaching         	    2000	    832391 ns/op
BenchmarkCacheGetSQLPostgreSQLWithoutEncryptionAndPrecaching-2       	    2000	    837306 ns/op
BenchmarkCacheGetSQLPostgreSQLWithoutEncryptionAndPrecaching-3       	    2000	    851568 ns/op
BenchmarkCacheGetSQLPostgreSQLWithoutEncryptionAndPrecaching-4       	    2000	    945629 ns/op
BenchmarkCacheGetSQLPostgreSQLWithEncryptionAndWithoutPrecaching     	    2000	   1037167 ns/op
BenchmarkCacheGetSQLPostgreSQLWithEncryptionAndWithoutPrecaching-2   	    2000	    860692 ns/op
BenchmarkCacheGetSQLPostgreSQLWithEncryptionAndWithoutPrecaching-3   	    2000	    934574 ns/op
BenchmarkCacheGetSQLPostgreSQLWithEncryptionAndWithoutPrecaching-4   	    2000	    932242 ns/op
BenchmarkCacheGetSQLPostgreSQLWithEncryptionAndPrecaching            	30000000	        39.6 ns/op
BenchmarkCacheGetSQLPostgreSQLWithEncryptionAndPrecaching-2          	30000000	        41.8 ns/op
BenchmarkCacheGetSQLPostgreSQLWithEncryptionAndPrecaching-3          	30000000	        38.6 ns/op
BenchmarkCacheGetSQLPostgreSQLWithEncryptionAndPrecaching-4          	30000000	        38.7 ns/op
BenchmarkCacheGetDirWithoutEncryptionAndPrecaching                   	   50000	     25212 ns/op
BenchmarkCacheGetDirWithoutEncryptionAndPrecaching-2                 	   50000	     28623 ns/op
BenchmarkCacheGetDirWithoutEncryptionAndPrecaching-3                 	   50000	     28575 ns/op
BenchmarkCacheGetDirWithoutEncryptionAndPrecaching-4                 	   50000	     28373 ns/op
BenchmarkCacheGetDirWithEncryptionAndWithoutPrecaching               	   50000	     26619 ns/op
BenchmarkCacheGetDirWithEncryptionAndWithoutPrecaching-2             	   50000	     30195 ns/op
BenchmarkCacheGetDirWithEncryptionAndWithoutPrecaching-3             	   50000	     30278 ns/op
BenchmarkCacheGetDirWithEncryptionAndWithoutPrecaching-4             	   50000	     30136 ns/op
BenchmarkCacheGetDirWithEncryptionAndPrecaching                      	30000000	        40.8 ns/op
BenchmarkCacheGetDirWithEncryptionAndPrecaching-2                    	30000000	        39.3 ns/op
BenchmarkCacheGetDirWithEncryptionAndPrecaching-3                    	30000000	        39.4 ns/op
BenchmarkCacheGetDirWithEncryptionAndPrecaching-4                    	30000000	        39.4 ns/op
PASS
ok  	jgocache/autocert/cache	60.091s

Documentation

Index

Constants

View Source
const (
	// CacheBackendDir specifies autocert's native DirCache caching backend
	// Which uses local directory for storing certificates
	CacheBackendDir string = "dir"

	// CacheBackendRedis specifies redis caching driver
	CacheBackendRedis string = "redis"

	// CacheBackendSQL specifies database/sql family of caching drivers(MySQL, PostgreSQL, etc.)
	CacheBackendSQL string = "sql"
)

Variables

This section is empty.

Functions

func NewCacheFactory

func NewCacheFactory(options map[string]string) (autocert.Cache, error)

NewCacheFactory returns Cache instance

Types

type Cache

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

Cache struct to store high level cache instance

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, key string) error

Delete calls backend's Delete method. If precache is used it will first delete from cache no matter if backend's Put completed successfully or failed.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string) ([]byte, error)

Get calls backend's Get to retrieve data from cache by key. If precaching is used Get will attempt to retrieve data from cache first, and if this attempt fails - will ask backend's Get to fill cache and return the data. If encryption is turned on Get will try to decrypt data retrieved from backend's Get before filling cache and returning the data.

func (*Cache) Put

func (c *Cache) Put(ctx context.Context, key string, data []byte) error

Put calls backend's Put to store the data to cache. If precache is used it will also fill cache if no errors returned by backend's Put. If encryption is turned on it will encrypt data before calling backend's Put, but precache will be filled with plaintext data.

Directories

Path Synopsis
sql

Jump to

Keyboard shortcuts

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