| 1 | =head1 NAME | ||||||||||
| 2 | |||||||||||
| 3 | Cache::RemovalStrategy::FIFO - FIFO Removal Strategy for a Cache | ||||||||||
| 4 | |||||||||||
| 5 | =head1 DESCRIPTION | ||||||||||
| 6 | |||||||||||
| 7 | Implements a First In First Out removal strategy for a Cache. When removing | ||||||||||
| 8 | entries from the cache, the 'oldest' will be removed first. | ||||||||||
| 9 | |||||||||||
| 10 | =head1 METHODS | ||||||||||
| 11 | |||||||||||
| 12 | See Cache::RemovalStrategy for details. | ||||||||||
| 13 | |||||||||||
| 14 | =cut | ||||||||||
| 15 | package Cache::RemovalStrategy::FIFO; | ||||||||||
| 16 | |||||||||||
| 17 | 2 | require 5.006; | |||||||||
| 18 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 2 | ▶ | use base qw(Cache::RemovalStrategy); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 2 | ▶ | use fields qw(); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 26 | 1 | my Cache::RemovalStrategy::FIFO $self = shift; | |||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | $self = fields::new($self) unless ref $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 1 | $self->SUPER::new(@_); | |||||||||
| 30 | |||||||||||
| 31 | 1 | return $self; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | 4 | ▶ | sub remove_size { | ||||||||
|
Subroutine
remove_size: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 36 | 4 | my Cache::RemovalStrategy::FIFO $self = shift; | |||||||||
| 37 | 4 | my ($cache, $size) = @_; | |||||||||
| 38 | |||||||||||
| 39 | 4 | ▶ | while ($size > 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 4 | my $removed = $cache->remove_oldest(); | |||||||||
| 41 | 4 | ▶ | defined $removed or last; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 4 | $size -= $removed; | |||||||||
| 43 | } | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | 2 | 1; | |||||||||
| 48 | __END__ | ||||||||||