# man > FileCache(3perl)

---
type: CommandReference
command: FileCache
mode: perldoc
section: 3perl
source: perldoc
---

## Quick Reference
- `use FileCache;` — enable automatic filehandle caching
- `use FileCache maxopen => 16;` — set maximum open files (default: system limit)
- `cacheout $path;` — open file for writing first time, append thereafter; returns $path
- `cacheout $mode, $path;` — open with specified mode; returns $path
- `print $path @data;` — use filehandle (path variable) directly after `cacheout`
- `$fh = cacheout $mode, $path;` — capture filehandle from cacheout
- `print $fh @data;` — use captured filehandle
- Supported modes: `>`, `+>`, `<`, `<+`, `>>`, `|-`, `-|`

## Name
FileCache - keep more files open than the system permits

## Synopsis
perl
no strict 'refs';
use FileCache;
# or
use FileCache maxopen => 16;

cacheout $mode, $path;
# or
cacheout $path;
print $path @data;

$fh = cacheout $mode, $path;
$fh = cacheout $path;
print $fh @data;
## Options
- `maxopen => N` — passed to `use FileCache`; sets the suggested maximum number of file descriptors to keep open (overrides system NOFILE)
- `cacheout EXPR` — 1-argument form: opens file for writing (`>`) on first use, appending (`>>`) thereafter
- `cacheout MODE, EXPR` — 2-argument form: uses supplied mode for initial and subsequent openings. Valid modes: `>`, `+>`, `<`, `<+`, `>>`, `|-`, `-|`. For piped modes (`|-`, `-|`), append arguments to the command string as in `system EXPR`
- Returns EXPR on success for convenience; EXPR can be used directly as a filehandle

## Examples
perl
use FileCache;
cacheout '/tmp/log.txt';
print '/tmp/log.txt' "Log entry\n";
perl
use FileCache maxopen => 32;
my $fh = cacheout '>', '/tmp/out.txt';
print $fh "Data\n";
perl
# Using piped open (discouraged)
cacheout '|-', 'gzip -c > /tmp/out.gz';
print '/tmp/out.gz' "Compressed data\n";
## Caveats
- Do not `close` a FileCache-managed filehandle directly unless using `FileCache::cacheout_close` (especially if called from a different package or if another module overrides `close`).
- Using FileCache with piped opens (`|-` or `-|`) is strongly discouraged: FileCache will re-execute the command if it needs to close and reopen the pipe, producing unexpected results. This feature may be removed in future releases.
- FileCache does not store the current file offset when closing a file; upon reopening, the offset is determined by the original `open` mode.
- The module relies on symbolic references; `use strict` will break without `no strict 'refs'`.

## See Also
[FileCache](https://perldoc.perl.org/FileCache) — Perl module documentation