> 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/it/piattaforma/cache.md).

# Cache

Utilizzi la cache a livello di server di PowerShell Universal con Set-PSUCache e Get-PSUCache, con informazioni sui tipi di scadenza, sulla cache persistente e sull'ambito Cache.

PowerShell Universal fornisce una cache a livello di server per condividere dati tra API, automazione e app. Imposti le voci della cache con `Set-PSUCache` e le recuperi con `Get-PSUCache`.

I valori della cache vengono serializzati con il serializzatore di PowerShell. Gli oggetti recuperati sono oggetti deserializzati e non istanze attive.

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

## Scadenza

Gli elementi della cache supportano la scadenza assoluta, relativa e scorrevole.

```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))
```

## Cache persistente

Utilizzi `-Persist` per archiviare una voce della cache nel database di PowerShell Universal. Le voci persistenti sopravvivono ai riavvii del servizio e sono disponibili per i server connessi che utilizzano lo stesso database.

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

### Crittografare i valori persistenti

Utilizzi `-Encrypt` con `-Persist` per crittografare il valore serializzato della cache prima che venga archiviato nel database. PowerShell Universal decrittografa automaticamente il valore quando `Get-PSUCache` lo recupera.

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

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

`-Encrypt` richiede `-Persist`; non può crittografare le voci della cache presenti solo in memoria. Utilizzi la cache persistente crittografata per i valori sensibili che devono essere condivisi tra i server o conservati dopo i riavvii. Continui a limitare l'accesso ai dati sensibili della cache con autorizzazioni e ruoli di lettura appropriati.

## Rimuovere le voci della cache

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

## Ambito $Cache

API, script di automazione e dashboard supportano le variabili `$Cache:` per i dati in memoria condivisi tra i runspace nello stesso ambiente di esecuzione.

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

`$Cache:` è separato dalla cache a livello di server. È limitato all'ambiente di esecuzione; per esempio, un valore della cache di una dashboard non è disponibile per un'API a meno che entrambi non utilizzino l'ambiente Integrated.

## Visualizzare la cache

Visualizzi le voci della cache a livello di server in **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/it/piattaforma/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.
