> 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

## SYNOPSIS

Sets an object into the PowerShell Universal server-side cache.

## SYNTAX

### None (Default)

```
Set-PSUCache -Key <String> -Value <Object> [-Persist] [-Role <String[]>] [-Depth <Int32>]
 [-ComputerName <String>] [-AppToken <String>] [-Credential <PSCredential>] [-UseDefaultCredentials]
 [-Integrated] [-TrustCertificate] [-Cookies] [<CommonParameters>]
```

### Absolute

```
Set-PSUCache -Key <String> -Value <Object> [-AbsoluteExpiration <DateTime>] [-Persist] [-Role <String[]>]
 [-Depth <Int32>] [-ComputerName <String>] [-AppToken <String>] [-Credential <PSCredential>]
 [-UseDefaultCredentials] [-Integrated] [-TrustCertificate] [-Cookies]
 [<CommonParameters>]
```

### AbsoluteExpirationFromNow

```
Set-PSUCache -Key <String> -Value <Object> [-AbsoluteExpirationFromNow <TimeSpan>] [-Persist]
 [-Role <String[]>] [-Depth <Int32>] [-ComputerName <String>] [-AppToken <String>] [-Credential <PSCredential>]
 [-UseDefaultCredentials] [-Integrated] [-TrustCertificate] [-Cookies]
 [<CommonParameters>]
```

### SlidingExpiration

```
Set-PSUCache -Key <String> -Value <Object> [-SlidingExpiration <TimeSpan>] [-Persist] [-Role <String[]>]
 [-Depth <Int32>] [-ComputerName <String>] [-AppToken <String>] [-Credential <PSCredential>]
 [-UseDefaultCredentials] [-Integrated] [-TrustCertificate] [-Cookies]
 [<CommonParameters>]
```

## DESCRIPTION

Sets an object into the PowerShell Universal server-side cache. This cmdlet is to be used within APIs, Dashboards and Scripts. You cannot retrieve cache data from the Management API.

## EXAMPLES

### Example 1

```powershell
PS C:\> Set-PSUCache -Key 'Data' -Value 'MyValue'
```

Caches data forever within the server-level cache.

### Example 2

```powershell
PS C:\> Set-PSUCache -Key 'Data' -Value 'MyValue' -AbsoluteExpiration (Get-Date).AddMinutes(10)
```

Caches data within the cache that will expire in 10 minutes.

### Example 3

```powershell
PS C:\> Set-PSUCache -Key 'Data' -Value 'MyValue' -AbsoluteExpirationFromNow [TimeSpan]::FromMinutes(30)
```

Caches data within the cache that will expire in 30 minutes.

### Example 4

```powershell
PS C:\> Set-PSUCache -Key 'Data' -Value 'MyValue' -SlidingExpiration [TimeSpan]::FromMinutes(10)
```

Caches data with a sliding cache of 10 minutes. If the data isn't accessed for 10 minutes, it will be invalidated and purged from the cache. If the data is accessed, the timer will reset for another 10 minutes.

## PARAMETERS

### -AbsoluteExpiration

An absolute expiration time for the data in the cache.

```yaml
Type: DateTime
Parameter Sets: Absolute
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -AbsoluteExpirationFromNow

A TimeSpan indicating how long from now the data should be removed from the cache.

```yaml
Type: TimeSpan
Parameter Sets: AbsoluteExpirationFromNow
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Key

A key for looking up the data in the cache.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -SlidingExpiration

A TimeSpan indicating the sliding expiration for data in the cache.

```yaml
Type: TimeSpan
Parameter Sets: SlidingExpiration
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Value

The object to store in the cache. This object will be serialized to CLIXML.

```yaml
Type: Object
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -AppToken

Specifies the app token to use when authenticating to the PowerShell Universal management API.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ComputerName

Specifies the URL or host name of the target PowerShell Universal instance. Bare host names are normalized to an http\://:5000 URL.

```yaml
Type: String
Parameter Sets: (All)
Aliases: Uri

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Integrated

Executes the command internally rather than using the Management API. Only works when running script from within PowerShell Universal.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -UseDefaultCredentials

Provides Windows Credentials when authenticating against PowerShell Universal.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Credential

Credentials to login to the PowerShell Universal Management API.

```yaml
Type: PSCredential
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Persist

Persists cache data to the database.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Role

The roles that have access to this cached data.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -TrustCertificate

Whether the cmdlet should ignore certificate issues.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Cookies

Reuses and persists authentication cookies for the current PowerShell session.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Depth

Specifies the serialization depth to use when converting values before sending them to the server.

```yaml
Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction. For more information, see [about\_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### None

## OUTPUTS

### System.Object

## NOTES

## RELATED LINKS

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


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
