InMemoryCache

package
v0.7.10 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const MaxRetention int64 = 60 * 60 * 24 * 365 * 10 // 10 years
View Source
const TenYears int64 = 60 * 60 * 24 * 365 * 10 // 10 years

Variables

View Source
var ErrInvalidConversion = errors.New("Invalid number converstion")
View Source
var ErrNoSpaceAvailable = errors.New("No space available on specified volumes")

Functions

func ConvertMGTPToValue

func ConvertMGTPToValue(in string) (u int64, err error)

func HeadersAllowCaching

func HeadersAllowCaching(hdr http.Header, duration int) (seconds int64, rawSeconds int64, mayCache bool)

----------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------- Return if this item can be cached and if so for how long.

Exampels of setting non-caching headers are:

www.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") // HTTP 1.1.
www.Header().Set("Pragma", "no-cache")                                   // HTTP 1.0.
www.Header().Set("Expires", "0")                                         // Proxies.

func PeriodicCleanup

func PeriodicCleanup(ti *TimedInMemoryCache, d int)

Duration 'd' is in seconds - indicates how often the cleanup process will happen. d==0, no cleanup.

Types

type EtClassType

type EtClassType int
const (
	EtagFromMarked EtClassType = 1
	EtagFromProxy  EtClassType = 2
	EtagFromLocal  EtClassType = 3
	EtagUnknown    EtClassType = 4
)

func ClasifyETag

func ClasifyETag(etag string) (etClass EtClassType)

return where the etag came from

func (EtClassType) String

func (et EtClassType) String() string

type InMemoryCacheType

type InMemoryCacheType struct {
	Next            http.Handler //
	Paths           []string     //
	Extensions      []string     // Legit extensions to cache
	Duration        int          // Time in seconds that data is kept in memory
	SizeLimit       int          // Size limit on how bit to cache
	IgnoreUrls      []string     // URLs that are to be specifically ignored
	DiskCache       []string     // Save stuff on disk at locations
	DiskSize        []string     // Sizes as strings 1G, 1M converted to values
	DiskSizeLimit   int          // Size limit per-file on disk - how big of individual file to cache
	DiskCleanupFreq int          // clean up on disk files - default is hourly
	LineNo          int          //
	RedisPrefix     string       //
	// contains filtered or unexported fields
}

func NewInMemoryCacheServer

func NewInMemoryCacheServer(n http.Handler, p []string, e []string, d int, sl int) *InMemoryCacheType

Parameterized for testing? or just change the test

func (*InMemoryCacheType) FoundInDiskCache

func (hdlr *InMemoryCacheType) FoundInDiskCache(url, hUrl string, www http.ResponseWriter, req *http.Request, rw *goftlmux.MidBuffer) bool

func (*InMemoryCacheType) FoundInMemoryCache

func (hdlr *InMemoryCacheType) FoundInMemoryCache(url, hUrl string, www http.ResponseWriter, req *http.Request, rw *goftlmux.MidBuffer) (found bool)

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

func (*InMemoryCacheType) GetExpiredFiles

func (hdlr *InMemoryCacheType) GetExpiredFiles() (kks []string, curTimeUnix string)

------------------------------------------------------------------------------------------------ Fetch the list of expired files and delete this from the list.

func (*InMemoryCacheType) GetFileName

func (hdlr *InMemoryCacheType) GetFileName(www http.ResponseWriter, id string, bod []byte) (fn string, err error)

func (*InMemoryCacheType) InCachePath

func (hdlr *InMemoryCacheType) InCachePath(fn string) bool

------------------------------------------------------------------------------------------------ comapre abs(cahce) path with fn prefix and if match then return true

func (*InMemoryCacheType) InitializeWithConfigData

func (hdlr *InMemoryCacheType) InitializeWithConfigData(next http.Handler, gCfg *cfg.ServerGlobalConfigType, serverName string, pNo, callNo int) (err error)

func (*InMemoryCacheType) PeriodicCleanupDiskFiles

func (hdlr *InMemoryCacheType) PeriodicCleanupDiskFiles()

DiskCleanupFreq int // clean up on disk files - default is hourly

func (*InMemoryCacheType) PreValidate

func (hdlr *InMemoryCacheType) PreValidate(gCfg *cfg.ServerGlobalConfigType, cfgData map[string]interface{}, serverName string, pNo, callNo int) (err error)

func (*InMemoryCacheType) SaveInDiskCache

func (hdlr *InMemoryCacheType) SaveInDiskCache(www http.ResponseWriter, req *http.Request, bod []byte, howLongToSave int64, rw *goftlmux.MidBuffer)

howLongToSave is in seconds into the futrue - need to convert this for ZADD to a meaningful time. Add in the current time since beginning of epoc, then if current time is larger(in-loop) can clean up file.

func (*InMemoryCacheType) ServeHTTP

func (hdlr *InMemoryCacheType) ServeHTTP(www http.ResponseWriter, req *http.Request)

func (*InMemoryCacheType) SpaceAvailable

func (hdlr *InMemoryCacheType) SpaceAvailable(path string, nth int, www http.ResponseWriter) bool

type MetaData

type MetaData struct {
	Id           string
	Etag         string
	FileName     string
	Hdr          http.Header
	RequestURL   string
	SentURI      string // xyzzy - will need to chagne this
	ModTime      time.Time
	ResolvedFn   string
	DependentFNs []string
	FileSource   string    // local, proxy
	TimeServed   time.Time // for marked files
}

func (*MetaData) FoundOnTheFarm

func (meta_data *MetaData) FoundOnTheFarm() (foundIt bool, fnInfo os.FileInfo)

if fnFound, fnInfo = FoundOnTheFarm ( meta_data ); !fnFound {

type TimedInMemoryCache

type TimedInMemoryCache struct {
	Cache   map[string]*TimedInMemoryData
	MapLock sync.Mutex // Lock for accesing maps in this.
}

func NewTimedInMemoryCache

func NewTimedInMemoryCache() (rv *TimedInMemoryCache)

func (*TimedInMemoryCache) DelContent

func (ti *TimedInMemoryCache) DelContent(url, hUrl string)

func (*TimedInMemoryCache) HaveContent

func (ti *TimedInMemoryCache) HaveContent(uri, hUrl string, d int, hdr http.Header) (to TimedInMemoryData, err error, found bool)

func (*TimedInMemoryCache) SaveContent

func (ti *TimedInMemoryCache) SaveContent(uri, hUrl string, d int, hdr http.Header, bod []byte, modtime time.Time, ResolvedFn string)

type TimedInMemoryData

type TimedInMemoryData struct {
	Buf        []byte      // body data
	Id         string      // Self SHA256 hash
	ModTime    time.Time   // When modified
	When       time.Time   // When fetched last
	Hdr        http.Header // Headers to return
	Hits       int         // how many times fetched
	ResolvedFn string      // If a file on disk, then this is the single file name
}

----------------------------------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------

Jump to

Keyboard shortcuts

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