> 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/es/plataforma/cache.md).

# Caché

Utilice la caché a nivel de servidor de PowerShell Universal con Set-PSUCache y Get-PSUCache, incluidos los tipos de expiración, la caché persistente y el ámbito Cache.

PowerShell Universal proporciona una caché a nivel de servidor para compartir datos entre API, automatización y aplicaciones. Establezca entradas de caché con `Set-PSUCache` y recupérelas con `Get-PSUCache`.

Los valores de la caché se serializan con el serializador de PowerShell. Los objetos recuperados son objetos deserializados y no instancias activas.

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

## Expiración

Los elementos de la caché admiten expiración absoluta, relativa y deslizante.

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

## Caché persistente

Utilice `-Persist` para almacenar una entrada de caché en la base de datos de PowerShell Universal. Las entradas persistentes sobreviven a los reinicios del servicio y están disponibles para los servidores conectados que utilizan la misma base de datos.

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

### Cifrar valores persistentes

Utilice `-Encrypt` con `-Persist` para cifrar el valor de caché serializado antes de que se almacene en la base de datos. PowerShell Universal descifra el valor automáticamente cuando `Get-PSUCache` lo recupera.

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

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

`-Encrypt` requiere `-Persist`; no puede cifrar entradas de caché solo en memoria. Utilice la caché persistente cifrada para valores sensibles que deban compartirse entre servidores o conservarse después de los reinicios. Siga limitando el acceso a los datos sensibles de la caché con los permisos y los roles de lectura adecuados.

## Eliminar entradas de caché

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

## Ámbito $Cache

Las API, los scripts de automatización y los paneles admiten variables `$Cache:` para datos en memoria compartidos entre runspaces del mismo entorno de ejecución.

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

`$Cache:` es independiente de la caché a nivel de servidor. Está limitado al entorno de ejecución; por ejemplo, un valor de caché de un panel no está disponible para una API a menos que ambos utilicen el entorno Integrated.

## Ver la caché

Vea las entradas de la caché a nivel de servidor en **Gestionar > Caché**.

## 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 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/es/plataforma/cache.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.
