---
name: "Mojo::Cache"
section: "3pm"
platform: "linux"
package: "libmojolicious-perl"
version: "9.39+dfsg-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Mojo::Cache"
---

# Mojo::Cache(3pm)

Naive in-memory cache

## NAME

Mojo::Cache - Naive in-memory cache

## SYNOPSIS

```
  use Mojo::Cache;
  my $cache = Mojo::Cache->new(max_keys => 50);
  $cache->set(foo => 'bar');
  my $foo = $cache->get('foo');
```

## DESCRIPTION

Mojo::Cache is a naive in-memory cache with size limits.

## ATTRIBUTES

Mojo::Cache implements the following attributes.

### max\_keys

```
  my $max = $cache->max_keys;
  $cache  = $cache->max_keys(50);
```

Maximum number of cache keys, defaults to `100`. Setting the value to `0` will disable caching.

## METHODS

Mojo::Cache inherits all methods from Mojo::Base and implements the following new ones.

### get

```
  my $value = $cache->get('foo');
```

Get cached value.

### set

```
  $cache = $cache->set(foo => 'bar');
```

Set cached value.

## SEE ALSO

Mojolicious, Mojolicious::Guides, \<https://mojolicious.org\>.
