> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/powershell-commands/set-psucache.md).

# Set-PSUCache

Set-PSUCache stores an object in the PowerShell Universal server-side cache, with configurable expiration, persistence, and role access.

## SYNOPSIS

Sets an object in the server-wide cache.

## SYNTAX

```powershell
Set-PSUCache -Key <String> -Value <Object> [-Persist] [-Encrypt] [-ReaderRole <String[]>] [-Depth <Int32>] [<ConnectionOptions>] [<CommonParameters>]
Set-PSUCache -Key <String> -Value <Object> [-AbsoluteExpiration <DateTime>] [-Persist] [-Encrypt] [-ReaderRole <String[]>] [-Depth <Int32>] [<ConnectionOptions>] [<CommonParameters>]
Set-PSUCache -Key <String> -Value <Object> [-AbsoluteExpirationFromNow <TimeSpan>] [-Persist] [-Encrypt] [-ReaderRole <String[]>] [-Depth <Int32>] [<ConnectionOptions>] [<CommonParameters>]
Set-PSUCache -Key <String> -Value <Object> [-SlidingExpiration <TimeSpan>] [-Persist] [-Encrypt] [-ReaderRole <String[]>] [-Depth <Int32>] [<ConnectionOptions>] [<CommonParameters>]
```

`<ConnectionOptions>`: `[-ComputerName <String>] [-AppToken <String>] [-Credential <PSCredential>] [-UseDefaultCredentials] [-Integrated] [-TrustCertificate] [-Cookies]`. `-Role` is an alias of `-ReaderRole`.

## DESCRIPTION

Serializes a value to CLIXML and stores it in the server-wide cache shared by APIs, apps, and scripts; this command also works through the Management API. Choose one expiration form, or omit one to cache without a configured expiration. Use `-Persist` for database-backed storage. `-Encrypt` requires `-Persist`; using it without persistence raises an error.

## EXAMPLES

```powershell
Set-PSUCache -Key 'Data' -Value 'MyValue'
Set-PSUCache -Key 'Data' -Value 'MyValue' -AbsoluteExpiration (Get-Date).AddMinutes(10)
Set-PSUCache -Key 'Data' -Value 'MyValue' -AbsoluteExpirationFromNow ([TimeSpan]::FromMinutes(30))
Set-PSUCache -Key 'Data' -Value 'MyValue' -SlidingExpiration ([TimeSpan]::FromMinutes(10))
Set-PSUCache -Key 'Data' -Value 'MyValue' -Persist -Encrypt
```

The second example expires in ten minutes, the third expires thirty minutes after creation, and the fourth expires ten minutes after its last access.

## PARAMETERS

| Parameter                    | Description                                                        |
| ---------------------------- | ------------------------------------------------------------------ |
| `-Key`                       | Required cache key.                                                |
| `-Value`                     | Required object, serialized to CLIXML.                             |
| `-AbsoluteExpiration`        | Fixed expiration date and time.                                    |
| `-AbsoluteExpirationFromNow` | Duration from now until expiration.                                |
| `-SlidingExpiration`         | Duration of inactivity before expiration; access resets the timer. |
| `-Persist`                   | Persists the cache item to the database.                           |
| `-Encrypt`                   | Encrypts the persisted item; requires `-Persist`.                  |
| `-ReaderRole`                | Roles allowed to read the item (alias `-Role`).                    |
| `-Depth`                     | Serialization depth (default 1).                                   |
| `-ComputerName`              | Target PSU server URL or host name (alias `-Uri`).                 |
| `-AppToken`                  | Management API app token.                                          |
| `-Credential`                | Management API credentials.                                        |
| `-UseDefaultCredentials`     | Uses current Windows credentials.                                  |
| `-Integrated`                | Uses the in-process management client.                             |
| `-TrustCertificate`          | Ignores certificate validation errors.                             |
| `-Cookies`                   | Reuses session authentication cookies.                             |

## RELATED LINKS

[Get-PSUCache](/powershell-universal/powershell-commands/get-psucache.md)

## PERMISSIONS

The access token requires `platform.cache/create` to set a cache value remotely, including when replacing an existing value.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.devolutions.net/powershell-universal/powershell-commands/set-psucache.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
