Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 55872fd8

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID 55872fd8048745f35fb1f5f48aae2bda20e324ca
  • Vorgänger 96717bed
  • Nachfolger 0a8ac1f3

SL::Request: Funktion zum Cachen von Objekten für Dauer des Requests

Unterschiede anzeigen:

SL/Request.pm
41 41
  return 'html';
42 42
}
43 43

  
44
sub cache {
45
  my ($self, $topic, $default) = @_;
46

  
47
  $topic = '::' . (caller(0))[0] . "::$topic" unless $topic =~ m{^::};
48

  
49
  $self->{_cache}           //= {};
50
  $self->{_cache}->{$topic} //= ($default // {});
51

  
52
  return $self->{_cache}->{$topic};
53
}
54

  
44 55
sub _store_value {
45 56
  my ($target, $key, $value) = @_;
46 57
  my @tokens = split /((?:\[\+?\])?(?:\.)|(?:\[\+?\]))/, $key;
......
533 544

  
534 545
For more information about layouts, see L<SL::Layout::Dispatcher>.
535 546

  
547
=item C<cache $topic[, $default ]>
548

  
549
Caches an item for the duration of the request. C<$topic> must be an
550
index name referring to the thing to cache. It is used for retrieving
551
it later on. If C<$topic> doesn't start with C<::> then the caller's
552
package name is prepended to the topic. For example, if the a from
553
package C<SL::StuffedStuff> calls with topic = C<get_stuff> then the
554
actual key will be C<::SL::StuffedStuff::get_stuff>.
555

  
556
If no item exists in the cache for C<$topic> then it is created and
557
its initial value is set to C<$default>. If C<$default> is not given
558
(undefined) then a new, empty hash reference is created.
559

  
560
Returns the cached item.
561

  
536 562
=back
537 563

  
538 564
=head1 SPECIAL FUNCTIONS

Auch abrufbar als: Unified diff