File: PlainHash.pm

package info (click to toggle)
libipc-pubsub-perl 0.29-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 176 kB
  • sloc: perl: 1,471; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 738 bytes parent folder | download | duplicates (4)
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
package IPC::PubSub::Cache::PlainHash;
use strict;
use warnings;
use base 'IPC::PubSub::Cache';

my %cache;

use constant new => __PACKAGE__;

sub fetch {
    my $self = shift;
    @cache{@_};
}

sub store {
    my ($self, $key, $val, $time, $expiry) = @_;
    $cache{$key} = [$time => $val];
}

sub publisher_indices {
    my ( $self, $chan ) = @_;
    +{ %{ $cache{$chan} || {} } };
}

sub add_publisher {
    my ($self, $chan, $pub) = @_;
    $cache{$chan}{$pub} = 0;
}

sub remove_publisher {
    my ($self, $chan, $pub) = @_;
    delete $cache{$chan}{$pub};
}

sub get_index {
    my ($self, $chan, $pub) = @_;
    $cache{$chan}{$pub};
}

sub set_index {
    my ($self, $chan, $pub, $idx) = @_;
    $cache{$chan}{$pub} = $idx;
}

1;