ascache

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const CacheModeReadOnly = "READONLY"

CacheModeReadWrite represents a cache configuration that only reads from the cache. It does not update the cache with new values.

View Source
const CacheModeReadWrite = "READWRITE"

CacheModeReadWrite represents a cache configuration that reads from and writes to the cache

View Source
const CacheModeWriteOnly = "WRITEONLY"

CacheModeReadWrite represents a cache configuration that only writes to the cache. It does not search for existing cached values

View Source
const HeaderAge = "Age"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age

View Source
const HeaderDate = "Date"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date

View Source
const HeaderExpires = "Expires"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires

View Source
const HeaderHannibalCache = "X-Hannibal-Cache"

Custom header used by Hannibal to indicate that the response was cached

View Source
const HeaderHannibalCacheDate = "X-Hannibal-Cache-Date"

Custom header used by Hannibal to indicate the date that the cached value was saved

View Source
const PropertyIsActor = "isActor"
View Source
const PropertyIsCollection = "isCollection"
View Source
const PropertyIsObject = "isObject"
View Source
const PropertyRelationHref = "relationHref"
View Source
const PropertyRelationType = "relationType"
View Source
const RelationTypeAnnounce = "Announce"

RelationTypeAnnounce labels a document that is an "Announce" of another document in the cache. This value mirrors the ActivityStream "Announce" type

View Source
const RelationTypeDislike = "Dislike"

RelationTypeDislike labels a document that is a "Dislike" of another document in the cache. This value mirrors the ActivityStream "Dislike" type

View Source
const RelationTypeLike = "Like"

RelationTypeLike labels a document that is a "Like" of another document in the cache. This value mirrors the ActivityStream "Like" type

View Source
const RelationTypeReply = "Reply"

RelationTypeReply labels a document that is a reply to another document in the cache

Variables

This section is empty.

Functions

func CalcRefreshDate

func CalcRefreshDate(loadDate int64, expirationDate int64) int64

CalcRefreshDate determines the date that a document should be refreshed, which is half the duration between the load time and the expiration time. At a minimum, refresh duration will not be any less than one day.

Types

type Client

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

func New

func New(innerClient streams.Client, collection *mongo.Collection, options ...ClientOptionFunc) *Client

New returns a fully initialized Client object

func (*Client) Delete

func (client *Client) Delete(url string) error

Delete removes a single document from the cache

func (*Client) IsReadWritable

func (client *Client) IsReadWritable() bool

IsReadWritable returns TRUE if the cache can be read and written

func (*Client) IsReadable

func (client *Client) IsReadable() bool

IsReadable returns TRUE if the client is configured to read from the cache

func (*Client) IsWritable

func (client *Client) IsWritable() bool

isWritable returns TRUE if the client is configured to write to the cache

func (*Client) Load

func (client *Client) Load(url string, options ...any) (streams.Document, error)

func (*Client) NotReadWritable

func (client *Client) NotReadWritable() bool

NotReadWritable returns TRUE if the cache cannot be read or written

func (*Client) NotReadable

func (client *Client) NotReadable() bool

NotReadable returns TRUE if the client is not configured to read from the cache

func (*Client) NotWritable

func (client *Client) NotWritable() bool

NotWritable returns TRUE if the client is not configured to write to the cache

func (*Client) Put

func (client *Client) Put(document streams.Document)

func (*Client) WithOptions

func (client *Client) WithOptions(options ...ClientOptionFunc)

type ClientOptionFunc

type ClientOptionFunc func(*Client)

func WithIgnoreHeaders

func WithIgnoreHeaders() ClientOptionFunc

WithIgnoreHeaders instructs the cache to ignore HTTP headers and always use the cache.

func WithObeyHeaders

func WithObeyHeaders() ClientOptionFunc

WithObeyHeaders instructs the cache to use HTTP headers to determine whether or not to use the cache.

func WithPurgeFrequency

func WithPurgeFrequency(seconds int64) ClientOptionFunc

WithPurgeFrequency option sets the frequency that expired documents will be purged from the cache

func WithReadOnly

func WithReadOnly() ClientOptionFunc

WithReadOnly option sets the client to read-only mode. The cache will only read values from the database, and will not write new values to the database.

func WithReadWrite

func WithReadWrite() ClientOptionFunc

WithReadWrite option sets the client to read+write mode

func WithWriteOnly

func WithWriteOnly() ClientOptionFunc

WithWriteOnly option sets the client to write-only mode. The cache will only write values to the database, and will not check the database for existing values.

type LoadConfig

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

LoadConfig is a configuration object that used by the Load() method. It is generated by combining a default value with any functional options that are passed to the Load() method.

func NewLoadConfig

func NewLoadConfig(options ...any) LoadConfig

NewLoadConfig creates a new LoadConfig object, and applies any functional options that are passed to it.

func (*LoadConfig) With

func (config *LoadConfig) With(options ...any)

With applies functional options to the LoadConfig object

type LoadOption

type LoadOption func(*LoadConfig)

LoadOption is a functional option that can be passed to the Load() method.

func WithForceReload

func WithForceReload() LoadOption

WithForceReload is a functional option that forces the cache to be reloaded from the source.

func WithoutForceReload

func WithoutForceReload() LoadOption

WithoutForceReload is a functional option that does not force the cache to be reloaded from the source.

type TaskClearExpired

type TaskClearExpired struct {
}

func (TaskClearExpired) Run

func (task TaskClearExpired) Run() error

type Value

type Value struct {

	// Original HTTP Response
	URLs       sliceof.String     `bson:"urls"`                 // One or more URLs used to retrieve this document
	Object     mapof.Any          `bson:"object"`               // Original document, parsed as a map
	HTTPHeader http.Header        `bson:"httpHeader,omitempty"` // HTTP headers that were returned with this document
	Statistics streams.Statistics `bson:"statistics,omitempty"` // Statistics about this document
	Metadata   mapof.Any          `bson:"metadata,omitempty"`   // Metadata about this document

	// Caching Rules
	Published   int64 `bson:"published"`   // Unix epoch seconds when this document was published
	Received    int64 `bson:"received"`    // Unix epoch seconds when this document was received by the cache
	Expires     int64 `bson:"expires"`     // Unix epoch seconds when this document is expired. After this date, it must be revalidated from the source.
	Revalidates int64 `bson:"revalidates"` // Unix epoch seconds when this document should be removed from the cache.
}

func NewValue

func NewValue() Value

func (Value) ShouldRevalidate

func (value Value) ShouldRevalidate() bool

ShouldRevalidate returns TRUE if the "RevalidatesDate" is in the past.

Jump to

Keyboard shortcuts

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