# man > Cache::SizeAwareCache

---
type: CommandReference
command: Cache::SizeAwareCache
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference
- `use Cache::SizeAwareCache;` — Load the size-aware cache interface.
- `push @ISA, 'Cache::SizeAwareCache';` — Inherit from the size-aware cache.
- `$cache->set_max_size(1048576);` — Set maximum cache size to 1 MB.
- `$cache->limit_size(524288);` — Trim cache to at most 512 KB.
- `use Cache::SizeAwareCache qw( $NO_MAX_SIZE );` — Import the constant for no size limit.

## Name
`Cache::SizeAwareCache` — extends the `Cache::Cache` interface with size-limiting features.

## Synopsis
perl
use Cache::SizeAwareCache;
use vars qw( @ISA );
@ISA = qw( Cache::SizeAwareCache );
## Options
All standard options from [`Cache::Cache`](https://perldoc.perl.org/Cache::Cache) are supported.

- `max_size` — Maximum cache size in bytes. Defaults to `$NO_MAX_SIZE`. Setting this triggers a size check on every `set`, which can be expensive. Prefer calling `limit_size()` periodically instead.

### Constants
- `$NO_MAX_SIZE` — Indicates no size restriction.

## Methods
Inherits all methods from [`Cache::Cache`](https://perldoc.perl.org/Cache::Cache). Additionally:

- `limit_size( $new_size )` — Attempt to resize the cache so total usage does not exceed `$new_size` bytes. This is a one-time adjustment. For ongoing size enforcement, use the `max_size` option or call `limit_size()` periodically.

## See Also
[`Cache::Cache`](https://perldoc.perl.org/Cache::Cache)