Help language development. Donate to The Perl Foundation

ObjectCache cpan:ELIZABETH last updated on 2021-01-30

use v6.c;
use Test;
use ObjectCache;

plan 7;

sub id(%h --> Int:D) {
    %h<id> or die "Must have an id";
class Article does ObjectCache[&id] {
    has $.id;

    method remove-from-cache() { self!EVICT }
    method clear-cache()       { self!CLEAR }

dies-ok { }, 'does absence of ID die';

my $object = => 42666789);
is-deeply $object.WHICH,"Article|42666789"),
  'is the basic .WHICH ok';

my $removed = $object.remove-from-cache;
is-deeply $removed.WHICH,"Article|42666789"),
  'does remove from cache return the object';

is-deeply $removed.remove-from-cache, Nil,
  'does removed object return Nil';

$object = => 42666789);
is-deeply $object.WHICH,"Article|42666789"),
  'is the basic .WHICH again ok';

my $object2 = => 42666789);
is-deeply $object2.WHICH,"Article|42666789"),
  'is the basic of second object .WHICH also ok';

is Article.clear-cache, 1, 'did we remove 1 object from cache';

# vim: expandtab shiftwidth=4