blob: 8d86471418eb91d72771133b38c21e2ce75d7d19 [file] [log] [blame]
package sample
// A Cache service mimics the memcache interface.
type Cache interface {
// Set sets a value for a key.
Set(key string, value any) error
// Get returns the value for a key. If the value is not found, returns
// a not found error.
Get(key string) (any, error)
// Same as Get, but casts the return argument to an byte.
GetAsByte(key string) (byte, error)
// Same as Get, but casts the return argument to an int32.
GetAsInt32(key string) (int32, error)
// Same as Get, but casts the return argument to an int64.
GetAsInt64(key string) (int64, error)
// Same as Get, but casts the return argument to an uint32.
GetAsUint32(key string) (uint32, error)
// Same as Get, but casts the return argument to an uint64.
GetAsUint64(key string) (uint64, error)
// Same as Get, but casts the return argument to an float32.
GetAsFloat32(key string) (float32, error)
// Same as Get, but casts the return argument to an float64.
GetAsFloat64(key string) (float64, error)
// Same as Get, but casts the return argument to a string.
GetAsString(key string) (string, error)
// Same as Get, but casts the return argument to a bool.
GetAsBool(key string) (bool, error)
// Same as Get, but casts the return argument to an error.
GetAsError(key string) (error, error)
// AsMap returns the full contents of the cache as a map.
AsMap() (map[string]any, error)
// KeyValuePairs returns the full contents of the cache as a slice of pairs.
KeyValuePairs() ([]KeyValuePair, error)
// MostRecentSet returns the key and value and the timestamp for the most
// recent set operation
// TODO(bprosnitz) support type types and change time to native time type
MostRecentSet() (value KeyValuePair, time int64, err error)
// KeyPage indexes into the keys (in alphanumerically sorted order) and
// returns the indexth page of 10 keys.
KeyPage(index int64) ([10]string, error)
// Size returns the total number of entries in the cache.
Size() (int64, error)
// MultiGet sets up a stream that allows fetching multiple keys.
MultiGet() stream<string, any> error
}
// KeyValuePair is a representation of a cached key and value pair.
type KeyValuePair struct {
Key string
Value any
}