Documentation ¶
Index ¶
- Constants
- func CalcRefreshDate(loadDate int64, expirationDate int64) int64
- type Client
- func (client *Client) Delete(url string) error
- func (client *Client) IsReadWritable() bool
- func (client *Client) IsReadable() bool
- func (client *Client) IsWritable() bool
- func (client *Client) Load(url string, options ...any) (streams.Document, error)
- func (client *Client) NotReadWritable() bool
- func (client *Client) NotReadable() bool
- func (client *Client) NotWritable() bool
- func (client *Client) Put(document streams.Document)
- func (client *Client) WithOptions(options ...ClientOptionFunc)
- type ClientOptionFunc
- type LoadConfig
- type LoadOption
- type TaskClearExpired
- type Value
Constants ¶
const CacheModeReadOnly = "READONLY"
CacheModeReadWrite represents a cache configuration that only reads from the cache. It does not update the cache with new values.
const CacheModeReadWrite = "READWRITE"
CacheModeReadWrite represents a cache configuration that reads from and writes to the cache
const CacheModeWriteOnly = "WRITEONLY"
CacheModeReadWrite represents a cache configuration that only writes to the cache. It does not search for existing cached values
const HeaderAge = "Age"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age
const HeaderDate = "Date"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date
const HeaderExpires = "Expires"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires
const HeaderHannibalCache = "X-Hannibal-Cache"
Custom header used by Hannibal to indicate that the response was cached
const HeaderHannibalCacheDate = "X-Hannibal-Cache-Date"
Custom header used by Hannibal to indicate the date that the cached value was saved
const PropertyIsActor = "isActor"
const PropertyIsCollection = "isCollection"
const PropertyIsObject = "isObject"
const PropertyRelationHref = "relationHref"
const PropertyRelationType = "relationType"
const RelationTypeAnnounce = "Announce"
RelationTypeAnnounce labels a document that is an "Announce" of another document in the cache. This value mirrors the ActivityStream "Announce" type
const RelationTypeDislike = "Dislike"
RelationTypeDislike labels a document that is a "Dislike" of another document in the cache. This value mirrors the ActivityStream "Dislike" type
const RelationTypeLike = "Like"
RelationTypeLike labels a document that is a "Like" of another document in the cache. This value mirrors the ActivityStream "Like" type
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 ¶
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) IsReadWritable ¶
IsReadWritable returns TRUE if the cache can be read and written
func (*Client) IsReadable ¶
IsReadable returns TRUE if the client is configured to read from the cache
func (*Client) IsWritable ¶
isWritable returns TRUE if the client is configured to write to the cache
func (*Client) NotReadWritable ¶
NotReadWritable returns TRUE if the cache cannot be read or written
func (*Client) NotReadable ¶
NotReadable returns TRUE if the client is not configured to read from the cache
func (*Client) NotWritable ¶
NotWritable returns TRUE if the client is not configured to write to the cache
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 (Value) ShouldRevalidate ¶
ShouldRevalidate returns TRUE if the "RevalidatesDate" is in the past.