> 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/da/platform/cache.md).

# Cache

Brug cachen på serverniveau i PowerShell Universal med Set-PSUCache og Get-PSUCache, herunder udløbstyper, vedvarende cachelagring og Cache-scopet.

PowerShell Universal leverer en cache på serverniveau til deling af data mellem API'er, automatisering og apps. Angiv cacheposter med `Set-PSUCache`, og hent dem med `Get-PSUCache`.

Cacheværdier serialiseres med PowerShell-serializeren. Hentede objekter er deserialiserede objekter snarere end live-instanser.

```powershell
Set-PSUCache -Key 'CurrentDate' -Value (Get-Date)
Get-PSUCache -Key 'CurrentDate'
```

## Udløb

Cacheelementer understøtter absolut, relativ og glidende udløb.

```powershell
Set-PSUCache -Key 'CurrentDate' -Value (Get-Date) -AbsoluteExpiration (Get-Date).AddMinutes(10)
Set-PSUCache -Key 'CurrentDate' -Value (Get-Date) -AbsoluteExpirationFromNow ([TimeSpan]::FromHours(1))
Set-PSUCache -Key 'CurrentDate' -Value (Get-Date) -SlidingExpiration ([TimeSpan]::FromMinutes(5))
```

## Vedvarende cache

Brug `-Persist` til at gemme en cachepost i PowerShell Universal-databasen. Persistente poster overlever genstart af tjenesten og er tilgængelige for forbundne servere, der bruger den samme database.

```powershell
Set-PSUCache -Key 'CurrentDate' -Value (Get-Date) -Persist
```

### Krypter persistente værdier

Brug `-Encrypt` sammen med `-Persist` til at kryptere den serialiserede cacheværdi, før den gemmes i databasen. PowerShell Universal dekrypterer værdien automatisk, når `Get-PSUCache` henter den.

```powershell
Set-PSUCache -Key 'ApiResponse' -Value $response -Persist -Encrypt

$response = Get-PSUCache -Key 'ApiResponse'
```

`-Encrypt` kræver `-Persist`; det kan ikke kryptere cacheposter, der kun findes i hukommelsen. Brug krypteret vedvarende cache til følsomme værdier, der skal deles på tværs af servere eller bevares efter genstart. Fortsæt med at begrænse adgangen til følsomme cachedata med passende tilladelser og læserroller.

## Fjern cacheposter

```powershell
Remove-PSUCache -Key 'CurrentDate'
Clear-PSUCache
```

## $Cache-omfang

API'er, automatiseringsscripts og dashboards understøtter `$Cache:`-variabler til data i hukommelsen, der deles på tværs af runspaces i det samme kørselsmiljø.

```powershell
$Cache:MyValue = 'Hello'
Write-Host $Cache:MyValue
```

`$Cache:` er adskilt fra cachen på serverniveau. Det er begrænset til kørselsmiljøet; for eksempel er en cacheværdi for et dashboard ikke tilgængelig for et API, medmindre begge bruger Integrated-miljøet.

## Vis cachen

Vis poster i cachen på serverniveau under **Manage > Cache**.

## API

* `Get-PSUCache`
* `Set-PSUCache`
* `Remove-PSUCache`
* `Clear-PSUCache`


---

# 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/da/platform/cache.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.
