This file is indexed.

/usr/share/perl5/Arch/SharedCache.pm is in libarch-perl 0.5.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Arch Perl library, Copyright (C) 2004 Mikhael Goikhman
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

use 5.005;
use strict;

package Arch::SharedCache;

use base 'Arch::SharedIndex';
use Arch::Util qw(save_file load_file);

sub new ($%) {
	my $class = shift;
	my %init = @_;

	my $dir = $init{dir} or die "No cache directory given\n";
	unless (-d $dir) {
		mkdir($dir, 0777) or die "Can't create cache directory $dir: $!\n";
	}
	-d $dir or die "No cache directory ($dir)\n";

	my $index_file = $init{index_file} || $init{file} || '.index';
	$index_file = "$dir/$index_file" unless $index_file =~ m!^\.?/!;

	my $self = $class->SUPER::new(
		# default to a more readable serialization output
		perl_data_indent => 1,
		perl_data_pair   => " => ",
		%init,
		file => $index_file,
	);
	$self->{dir} = $dir;
	$self->{generic_filenames} = $init{generic_filenames} || 0;

	return $self;
}

sub generate_unique_token ($) {
	my $self = shift;
	my $dir = $self->{dir};
	my $prefix = time() . "-";
	my $token = $prefix . "000000";
	return $token unless -e "$dir/$token";
	my $tries = 1000000;
	do {
		$token = $prefix . sprintf("%06d", rand(1000000));
	} while -e "$dir/$token" && --$tries;
	die "Failed to acquire unused file name $dir/$prefix*\n" unless $tries;
	return $token;
}

sub file_name_by_token ($$) {
	my $self = shift;
	my $token = shift;
	$token =~ s!/!%!g;
	return "$self->{dir}/$token";
}

sub delete_value ($$$) {
	my $self = shift;
	my ($key, $token) = @_;
	$token = $key if $token eq "";
	my $file_name = $self->file_name_by_token($token);
	return unless -e $file_name;
	unlink($file_name) or warn "Can't unlink $file_name: $!\n";
}

sub fetch_value ($$$) {
	my $self = shift;
	my ($key, $token) = @_;
	$token = $key if $token eq "";
	my $file_name = $self->file_name_by_token($token);
	my $value = eval { load_file($file_name); };
	warn $@ if $@;
	$self->decode_value(\$value);
	return $value;
}

sub store_value ($$$) {
	my $self = shift;
	my ($key, $token, $value) = @_;
	$token = $key
		if defined $token && $token eq "";
	$token = $key
		if !defined $token && !$self->{generic_filenames};
	$token = $self->generate_unique_token
		if !defined $token || $token eq "";
	my $file_name = $self->file_name_by_token($token);
	$self->encode_value(\$value);
	eval { save_file($file_name, \$value); };
	warn $@ if $@;
	$token = "" if $key eq $token;
	$token = undef if $@;
	return $token;
}

1;

__END__

=head1 NAME

Arch::SharedCache - a synchronized data structure (map) for IPC

=head1 SYNOPSIS

    use Arch::SharedCache;

    my $cache = Arch::SharedCache->new(
        dir => '/tmp/dir-listings',
        max_size   => 100,
        expiration => 600,  # 10 minutes
    );

    sub ls_long { scalar `ls -l $_[0]` }

    my $user_dir = '/usr/share';
    $cache->store($user_dir => ls_long($user_dir));
    $cache->fetch_store(sub { ls_long($_[0]) }, qw(/tmp /bin /usr/share));
    printf "Cached listing of $user_dir:\n%s", $cache->fetch($user_dir);
    $cache->delete($user_dir);

    # examine /tmp/dir-listings/ after running this script
    # see also synopsys of Arch::SharedIndex

=head1 DESCRIPTION

Arch::SharedCache provides an Arch::SharedIndex implementation using a
single file per value.

=head1 METHODS

The following methods are available:

B<new>.

Other methods are documented in L<Arch::SharedIndex>.

=over 4

=item B<new> I<options>

Create a new Arch::SharedCache object.  I<options> is a hash of options.

=over 4

=item B<dir>

The cache directory used to store data.  Will be created if it doesn't exist.

=item B<index_file>

Name of the index file for the cache.  Defaults to C<B<dir>/.index>.

=back

=back

=head1 BUGS

Awaiting for your reports.

=head1 AUTHORS

Mikhael Goikhman (migo@homemail.com--Perl-GPL/arch-perl--devel).

Enno Cramer (uebergeek@web.de--2003/arch-perl--devel).

=head1 SEE ALSO

For more information, see L<Arch::SharedIndex>.

=cut