File: Base.pm

package info (click to toggle)
rex 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,688 kB
  • ctags: 2,045
  • sloc: perl: 29,512; xml: 264; makefile: 7
file content (75 lines) | stat: -rw-r--r-- 1,135 bytes parent folder | download
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
#
# (c) Jan Gehring <jan.gehring@gmail.com>
#
# vim: set ts=2 sw=2 tw=0:
# vim: set expandtab:

package Rex::Interface::Cache::Base;

use strict;
use warnings;

our $VERSION = '1.4.1'; # VERSION

use Rex::Logger;
use Rex;

sub new {
  my $that  = shift;
  my $proto = ref($that) || $that;
  my $self  = {@_};

  bless( $self, $proto );

  return $self;
}

sub gen_key_name {
  my ( $self, $key_name ) = @_;
  return $key_name if $key_name;

  my ( $package, $filename, $line, $subroutine ) = caller(1);

  $package =~ s/::/_/g;

  my $gen_key_name = "\L${package}_\L${subroutine}";

  return $gen_key_name;
}

sub set {
  my ( $self, $key, $val, $timeout ) = @_;

  if ( Rex::Config->get_use_cache ) {
    $self->{__data__}->{$key} = $val;
  }
}

sub valid {
  my ( $self, $key ) = @_;
  return exists $self->{__data__}->{$key};
}

sub get {
  my ( $self, $key ) = @_;
  return $self->{__data__}->{$key};
}

sub reset {
  my ($self) = @_;
  $self->{__data__} = {};
}

# have to be overwritten by subclass
sub save {
  my ($self) = @_;
  return 1;
}

# have to be overwritten by subclass
sub load {
  my ($self) = @_;
  return 0;
}

1;