---
title: GetOrSetEntry
summary: GetOrSetEntry retrieves the object stored in the cache for the given key if it exists, or inserts and returns the contents provided in the CacheEntry.
url: https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/cache/simple/fn.GetOrSetEntry/
---

**Kind:** Function  
**Module:** [simple](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/cache/simple/)  
**Package:** compute-sdk-go v1.11.0  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/cache/simple/simple.go#L120

```go
func GetOrSetEntry(key []byte, entry CacheEntry) (io.ReadCloser, error)
```

GetOrSetEntry retrieves the object stored in the cache for the given
key if it exists, or inserts and returns the contents provided in the
[CacheEntry](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/cache/simple/struct.CacheEntry/).

The cache entry is only inserted when no value is present for the
key, and no other client is in the process of setting it.

If the cache entry body content is costly to compute, consider using
[GetOrSet](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/cache/simple/fn.GetOrSet/) instead to avoid creating its [io.Reader](https://pkg.go.dev/io#Reader) in the case
where the value is already present.

The returned [io.ReadCloser](https://pkg.go.dev/io#ReadCloser) must be closed by the caller when
finished.

**Parameters**

- `key`: `[]byte`
- `entry`: `CacheEntry`

**Returns**

`(io.ReadCloser, error)`
