PPI::Cache(3)

πŸ’– PPI::Cache β€” The PPI Document Caching Layer πŸ’–

okay bestie, so this is PPI::Cache, a page from the User Contributed Perl Documentation collection, and it is exactly what it sounds like: the caching layer for PPI documents. no cap. let's get into it πŸ¦‹


✨ SYNOPSIS ✨

# Set the cache
use PPI::Cache path => '/var/cache/ppi-cache';

# Manually create a cache
my $Cache = PPI::Cache->new(
    path     => '/var/cache/perl/class-PPI',
    readonly => 1,
);

like, that's the whole vibe. two ways in, both iconic πŸ’…


🌸 DESCRIPTION 🌸

PPI::Cache is the default caching functionality for PPI. it's giving "background support system that nobody notices but everyone needs."

the way it works is: it integrates automatically with PPI itself. once you've enabled it, literally any attempt to load a document from the filesystem gets cached via cache. no extra steps, no asking, it just does it. periodt.

⚠️ but heads up bestie β€” creating a PPI::Document from raw source, or from some other object, will not be cached. only the filesystem-load path gets the treatment. don't come for me, that's just what the page says 😭

πŸŽ€ Using PPI::Cache

the most common way to use PPI::Cache is to hand parameters straight to the use statement at the top of your program. main character energy, honestly.

# Load the class but do not set a cache
use PPI::Cache;

# Use a fairly normal cache location
use PPI::Cache path => '/var/cache/ppi-cache';

and here's the slay part: any of the arguments that can be provided to the new constructor can also be provided to use. so whatever you can do down there, you can do up here. πŸ’«


πŸ”₯ METHODS πŸ”₯

πŸ’œ new param => $value, ...

the new constructor creates a new standalone cache object. it's a whole independent thing, living its best life.

it takes a number of parameters to control the cache:

  • path β€” the path param sets the base directory for the cache. it must already exist, and it must be writable. no path, no cache, that's the rule 🚫
  • readonly β€” the readonly param is a true/false flag that allows the use of an existing cache by a less-privileged user (such as the web user). existing documents will be retrieved from the cache, but new documents will not be written to it. so it's read-only mode, literally the name πŸ’…

returns a new PPI::Cache object, or dies on error. dramatic but fair.


πŸ’œ path

the path accessor returns the path on the local filesystem that is the root of the cache. that's it. that's the method. queen of brevity πŸ‘‘


πŸ’œ readonly

the readonly accessor returns true if documents should not be written to the cache. true means hands off, no writing. 🫢


πŸ’œ get_document $md5sum | \$source

the get_document method checks to see if a Document is stored in the cache and retrieves it if so. it's the "do we already have this?" check, and it accepts either an $md5sum or a reference to the \$source. πŸ’–


πŸ’œ store_document $Document

the store_document method takes a PPI::Document as argument and explicitly adds it to the cache. it's the "put this in the vault" move.

returns true if saved, or undef (or dies) on error. yes, or. both. we don't know which. iconic ambiguity honestly.

πŸ› FIXME (make this return either one or the other, not both) β€” the original page literally says this, so here it is in all its chaotic glory. not me fixing it, just reporting it fr fr 😭

🌈 TO DO 🌈

  • Finish the basic functionality
  • Add support for use PPI::Cache auto-setting $PPI::Document::CACHE

(we love a to-do list that's been sitting there. respect. 🧚)


⭐ SUPPORT ⭐

See the support section in the main module. that's the whole thing, go check the main module bestie.


πŸ‘‘ AUTHOR πŸ‘‘

Adam Kennedy <adamk@cpan.org>


Copyright 2005 - 2011 Adam Kennedy.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.


and that's the whole page, bestie!! πŸŽ€ this one shipped with perl v5.42.0 and got stamped 2026-01-17, so go forth, cache your documents, and remember: read-only is a lifestyle, not a limitation πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from