Functionin corecompute-sdk-go v1.11.0View source
func Insert(key []byte, opts WriteOptions) (WriteCloseAbandoner, error)

Insert creates a WriteCloseAbandoner used for inserting an object into the cache for the given key. For the insertion to complete successfully, the object must be fully written to the writer and its Close method called.

If Close is not called, or the writer's Abandon method is called, the insertion is incomplete and any concurrent lookups that may be reading from the object as it is streamed into the cache may encounter an error while reading.

Unlike Transaction.Insert, this does not coordinate with any other lookups or inserts for this key. Concurrent inserts may race with concurrent lookups or insertions, and will unconditionally overwrite existing cached items rather than allowing for revalidation of an existing object.

Parameters

key: []byte
opts: WriteOptions

Returns

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const (
key = "my_key"
contents = "my cached object"
)
w, err := core.Insert([]byte(key), core.WriteOptions{
TTL: time.Hour,
SurrogateKeys: []string{key},
Length: uint64(len(contents)),
})
if err != nil {
panic(err)
}
if _, err := io.WriteString(w, contents); err != nil {
panic(err)
}
if err := w.Close(); err != nil {
panic(err)
}