summaryrefslogtreecommitdiff
path: root/lib/MON/Cache.pm
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2015-01-02 14:00:56 +0100
committerPaul Buetow <paul@buetow.org>2015-01-02 14:00:56 +0100
commit4f27f3ea59baa6cfca0ac1df96b1dfedbd83706c (patch)
tree79754e3c49216f80cb3ad5579851fca0bf1a31c9 /lib/MON/Cache.pm
initial
Diffstat (limited to 'lib/MON/Cache.pm')
-rw-r--r--lib/MON/Cache.pm55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/MON/Cache.pm b/lib/MON/Cache.pm
new file mode 100644
index 0000000..21b59f5
--- /dev/null
+++ b/lib/MON/Cache.pm
@@ -0,0 +1,55 @@
+package MON::Cache;
+
+use strict;
+use warnings;
+use v5.10;
+use autodie;
+
+use Data::Dumper;
+
+use MON::Display;
+use MON::Config;
+use MON::Utils;
+
+our @ISA = ('MON::Display');
+
+sub new {
+ my ( $class, %opts ) = @_;
+
+ my $self = bless \%opts, $class;
+
+ $self->init();
+
+ return $self;
+}
+
+sub init {
+ my ($self) = @_;
+
+ $self->clear();
+
+ return undef;
+}
+
+sub clear {
+ my ($self) = @_;
+
+ $self->{cache} = {};
+
+ return undef;
+}
+
+sub magic {
+ my ( $self, $key, $sub ) = @_;
+
+ my $cache = $self->{cache};
+
+ if ( exists $cache->{$key} ) {
+ $self->verbose("Delivering '$key' from cache");
+ return $cache->{$key};
+ }
+
+ return $cache->{$key} = $sub->();
+}
+
+1;