backends

package
v0.4.4-0...-300e47e Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGroupCachePool

func GetGroupCachePool() *groupcache.HTTPPool

GetGroupCachePool gets the groupcache's httppool

func InitGroupCacheRes

func InitGroupCacheRes(maxSize int) error

InitGroupCacheRes init the resources for groupcache init this in the handler provision stage.

func InitRedisClient

func InitRedisClient(addr, password string, db int) error

InitRedisClient inits the client for the redis

func NewNoPreCollectError

func NewNoPreCollectError(msg string) error

NewNoPreCollectError new a NoPreCollectError error

func ParseRedisConfig

func ParseRedisConfig(connSetting string) (*redis.Options, error)

ParseRedisConfig parses the connection settings string from the caddyfile

func ReleaseGroupCacheRes

func ReleaseGroupCacheRes() error

ReleaseGroupCacheRes releases the resources the memory backend collects

Types

type Backend

type Backend interface {
	io.Writer
	io.Closer
	Length() int
	Clean() error
	Flush() error
	GetReader() (io.ReadCloser, error)
}

Backend is the cache storage backend.

func NewFileBackend

func NewFileBackend(path string) (Backend, error)

NewFileBackend new a disk storage backend

func NewInMemoryBackend

func NewInMemoryBackend(ctx context.Context, key string, expiration time.Time) (Backend, error)

NewInMemoryBackend get the singleton of groupcache

func NewRedisBackend

func NewRedisBackend(ctx context.Context, key string, expiration time.Time) (Backend, error)

NewRedisBackend new a redis backend for cache's storage

func WrapResponseWriterToBackend

func WrapResponseWriterToBackend(w http.ResponseWriter) Backend

WrapResponseWriterToBackend wrap the responseWriter to match the backend's interface

type Base

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

Base wraps the http.ResponseWriter to match the Backend interface

func (*Base) Clean

func (b *Base) Clean() error

Clean base backend no need to perform cleanup

func (*Base) Close

func (b *Base) Close() error

Close base backend no need to release resource

func (*Base) Flush

func (b *Base) Flush() error

Flush flushes buffered data to the client

func (*Base) GetReader

func (b *Base) GetReader() (io.ReadCloser, error)

GetReader no reader for base backend

func (*Base) Length

func (b *Base) Length() int

Length base backend no length property

func (*Base) Write

func (b *Base) Write(p []byte) (n int, err error)

Write writes the content in the inner response

type FileBackend

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

FileBackend saves the content into a file

func (*FileBackend) Clean

func (f *FileBackend) Clean() error

Clean performs the purge storage

func (*FileBackend) Close

func (f *FileBackend) Close() error

Close performs the file close

func (*FileBackend) Flush

func (f *FileBackend) Flush() error

Flush syncs the underlying file

func (*FileBackend) GetReader

func (f *FileBackend) GetReader() (io.ReadCloser, error)

GetReader get the ReadCloser from the file backend

func (*FileBackend) Length

func (f *FileBackend) Length() int

Length return the cache content's length

func (*FileBackend) Write

func (f *FileBackend) Write(p []byte) (n int, err error)

Write writes the content to file

type FileReader

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

FileReader is the common code to read the storages until the subscription channel is closed

func (*FileReader) Close

func (r *FileReader) Close() error

Close closes the underlying storage

func (*FileReader) Read

func (r *FileReader) Read(p []byte) (n int, err error)

Read reads the content

type InMemoryBackend

type InMemoryBackend struct {
	Ctx context.Context
	Key string
	// contains filtered or unexported fields
}

InMemoryBackend saves the content into memory with the groupcache.

func (*InMemoryBackend) Clean

func (i *InMemoryBackend) Clean() error

Clean performs the purge storage

func (*InMemoryBackend) Close

func (i *InMemoryBackend) Close() error

Close write the temp buffer's content to the groupcache

func (*InMemoryBackend) Flush

func (i *InMemoryBackend) Flush() error

Flush do nothing here

func (*InMemoryBackend) GetReader

func (i *InMemoryBackend) GetReader() (io.ReadCloser, error)

GetReader return a reader for the write public response

func (*InMemoryBackend) Length

func (i *InMemoryBackend) Length() int

Length return the cache content's length

func (*InMemoryBackend) Write

func (i *InMemoryBackend) Write(p []byte) (n int, err error)

Write adds the response content in the context for the groupcache's setter function.

type NoPreCollectError

type NoPreCollectError struct {
	Content string
}

NoPreCollectError is a custom error when there is no precollect content in memory cache.

func (NoPreCollectError) Error

func (e NoPreCollectError) Error() string

Error return the error message

type RedisBackend

type RedisBackend struct {
	Ctx context.Context
	Key string
	// contains filtered or unexported fields
}

RedisBackend saves the content into redis

func (*RedisBackend) Clean

func (r *RedisBackend) Clean() error

Clean performs the purge storage

func (*RedisBackend) Close

func (r *RedisBackend) Close() error

Close write the temp buffer's content to the groupcache

func (*RedisBackend) Flush

func (r *RedisBackend) Flush() error

Flush do nothing here

func (*RedisBackend) GetReader

func (r *RedisBackend) GetReader() (io.ReadCloser, error)

GetReader return a reader for the write public response

func (*RedisBackend) Length

func (r *RedisBackend) Length() int

Length return the cache content's length

func (*RedisBackend) Write

func (r *RedisBackend) Write(p []byte) (n int, err error)

Write writes the response content in a temp buffer

type Subscription

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

Subscription ..

func NewSubscription

func NewSubscription() *Subscription

NewSubscription new a subscription for file backend

func (*Subscription) Close

func (s *Subscription) Close()

Close closes all the subscribers

func (*Subscription) NewSubscriber

func (s *Subscription) NewSubscriber() <-chan int

NewSubscriber add a new subscriber in the subscribers container

func (*Subscription) NotifyAll

func (s *Subscription) NotifyAll(newBytes int)

NotifyAll notify all subscribers with the signal

func (*Subscription) RemoveSubscriber

func (s *Subscription) RemoveSubscriber(subscriber <-chan int)

RemoveSubscriber remove the subscriber from the list

func (*Subscription) WaitAll

func (s *Subscription) WaitAll()

WaitAll waits all subscription are closed

Jump to

Keyboard shortcuts

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