.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HTML::Mason::Cache::BaseCache 3pm" .TH HTML::Mason::Cache::BaseCache 3pm 2024-03-05 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME HTML::Mason::Cache::BaseCache \- Base cache object .SH DESCRIPTION .IX Header "DESCRIPTION" This is the base module for all cache implementations used in Mason. It provides a few additional methods on top of \f(CW\*(C`Cache::BaseCache\*(C'\fR in Dewitt Clinton's \f(CW\*(C`Cache::Cache\*(C'\fR package. .PP An object of this class is returned from \f(CW$m\fR\->cache. .SH METHODS .IX Header "METHODS" .IP "clear ()" 4 .IX Item "clear ()" Remove all values in the cache. .IP "get (key, [%params])" 4 .IX Item "get (key, [%params])" Returns the value associated with \fIkey\fR or undef if it is non-existent or expired. This is extended with the following optional name/value parameters: .RS 4 .IP "busy_lock => duration" 4 .IX Item "busy_lock => duration" If the value has expired, set its expiration time to the current time plus \&\fIduration\fR (instead of removing it from the cache) before returning undef. This is used to prevent multiple processes from recomputing the same expensive value simultaneously. The \fIduration\fR may be of any form acceptable to set. .IP "expire_if => sub" 4 .IX Item "expire_if => sub" If the value exists and has not expired, call \fIsub\fR with the cache object as a single parameter. If \fIsub\fR returns a true value, expire the value. .RE .RS 4 .RE .IP "get_object (key)" 4 .IX Item "get_object (key)" Returns the underlying \f(CW\*(C`Cache::Object\*(C'\fR object associated with \fIkey\fR. The most useful methods on this object are .Sp .Vb 3 \& $co\->get_created_at(); # when was object stored in cache \& $co\->get_accessed_at(); # when was object last accessed \& $co\->get_expires_at(); # when does object expire .Ve .IP "expire (key)" 4 .IX Item "expire (key)" Expires the value associated with \fIkey\fR, if it exists. Differs from remove only in that the cache object is left around, e.g. for retrieval by get_object. .IP "remove (key)" 4 .IX Item "remove (key)" Removes the cache object associated with \fIkey\fR, if it exists. .IP "set (key, data, [duration])" 4 .IX Item "set (key, data, [duration])" Associates \fIdata\fR with \fIkey\fR in the cache. \fIduration\fR indicates the time until the value should be erased. If \&\fIduration\fR is unspecified, the value will never expire by time. .Sp \&\fR\f(CI$expires_in\fR\fI\fR may be a simple number of seconds, or a string of the form "[number] [unit]", e.g., "10 minutes". The valid units are s, second, seconds, sec, m, minute, minutes, min, h, hour, hours, d, day, days, w, week, weeks, M, month, months, y, year, and years.