There aren't any cache modules any longer.

This commit is contained in:
Colin Kuskie 2010-05-07 15:03:32 -07:00
parent 22f9a209bd
commit ea17973b30
3 changed files with 0 additions and 339 deletions

145
t/Cache.t
View file

@ -1,145 +0,0 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Write a little about what this script tests.
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/lib";
use Test::More;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Cache;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 11; # Increment this number for each test you create
#----------------------------------------------------------------------------
my $cache = WebGUI::Cache->new($session, 1);
isa_ok($cache, 'WebGUI::Cache');
is($cache->parseKey("andy"), $session->config->getFilename.":andy", "parseKey single key");
is($cache->parseKey(["andy","red"]), $session->config->getFilename.":andy:red", "parseKey composite key");
$cache->set("Shawshank","Prison");
is($cache->get("Shawshank"), "Prison", "set/get");
$cache->set(["andy", "dufresne"], "Prisoner");
is($cache->get(["andy", "dufresne"]), "Prisoner", "set/get composite");
my ($a, $b) = @{$cache->mget(["Shawshank",["andy", "dufresne"]])};
is($a, "Prison", "mget first value");
is($b, "Prisoner", "mget second value");
$cache->delete("Shawshank");
is(eval{$cache->get("Shawshank")}, undef, 'delete');
$cache->flush;
is(eval{$cache->get(["andy", "dufresne"])}, undef, 'flush');
$cache->setByHttp("http://www.google.com/");
cmp_ok($cache->get("http://www.google.com/"), 'ne', '', 'setByHttp');
my $longValue ='abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
abcdefghijklmnopqrstuvwxyz 0123456789 !@#$%^&*(
';
$cache->set("really-long-value",$longValue);
is($cache->get("really-long-value"), $longValue, "set/get really long value");
#----------------------------------------------------------------------------
# Cleanup
END {
}
#vim:ft=perl

View file

@ -1,79 +0,0 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Write a little about what this script tests.
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Storable qw(freeze thaw);
use Test::More;
use Time::HiRes;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Cache::Database;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
# presupposes that there are cached items to test
my $cacheEntries = $session->db->buildArrayRefOfHashRefs("select expires,cachekey,namespace,content from cache order by rand() limit 100");
#----------------------------------------------------------------------------
# Tests
plan tests => 2 + scalar(@{$cacheEntries}); # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
my $cache = WebGUI::Cache::Database->new($session, "this", "that");
my $testValue = "a rock that has no earthly business in that field";
$cache->set($testValue);
is($cache->get, $testValue, "set/get works");
$cache->delete;
is($cache->get, undef, "delete works");
# performance tests
my $numTests = 0;
my $totalTime = 0;
foreach my $entry (@{$cacheEntries}) {
my $start = [Time::HiRes::gettimeofday];
my $cache = WebGUI::Cache::Database->new($session, $entry->{cachekey}, $entry->{namespace});
$cache->{_key} = $entry->{cachekey}; # evil: don't do this at home kids
my $value = $cache->get;
if ($entry->{expires} > time()) {
my $entryValue = $entry->{content};
eval { $entryValue = thaw($entryValue); };
$entryValue = ($entryValue && ref $entryValue) ? $$entryValue : undef;
is_deeply($value, $entryValue, "cache entry is valid");
}
else {
is($value, undef, "cache entry has timed out");
}
$numTests++;
$totalTime += Time::HiRes::tv_interval($start);
}
print "\nTime to run $numTests cache tests is $totalTime seconds. Average time per test is ".($totalTime/$numTests)." seconds.\n" if ($numTests > 0);
# end performance tests
#----------------------------------------------------------------------------
# Cleanup
END {
}

View file

@ -1,115 +0,0 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Write a little about what this script tests.
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use Test::Deep;
use Path::Class;
use File::Path;
use File::Basename qw(basename);
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Cache;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 14;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
# put your tests here
my $origCacheType = $session->config->get('cacheType');
$session->config->set('cacheType', 'WebGUI::Cache::FileCache');
my $origCacheRoot = $session->config->get('fileCacheRoot');
$session->config->delete('fileCacheRoot');
my $loaded = use_ok('WebGUI::Cache::FileCache');
SKIP: {
skip 'Unable to load module WebGUI::Cache::FileCache', $tests unless $loaded;
my $cacher = WebGUI::Cache->new($session, 'ReservedForTests');
isa_ok($cacher, 'WebGUI::Cache::FileCache', 'WebGUI::Cache creates the correct object type');
isa_ok($cacher->session, 'WebGUI::Session', 'session method returns a session object');
cmp_deeply(
$cacher,
noclass({
_session => ignore(),
_namespace => basename(WebGUI::Test->file),
_key => re('[a-zA-Z0-9+\-]{22}'),
}),
'New FileCache object has correct defaults',
);
$cacher = WebGUI::Cache->new($session, 'ReservedForTests', 'ReservedForTests');
cmp_deeply(
$cacher,
noclass({
_session => ignore(),
_namespace => 'ReservedForTests',
_key => re('[a-zA-Z0-9+\-]{22}'),
}),
'Second fileCache object was recreated with custom namespace',
);
my $root = '/tmp'; ##Default for Unix testing. Need to extend this for Windows someday...
my $namespace = Path::Class::Dir->new($root, qw/WebGUICache ReservedForTests/);
is($cacher->getNamespaceRoot, $namespace->stringify, 'getNamespaceRoot returns the correct path');
ok(! -e $cacher->getNamespaceRoot, 'The namespace does not exist in the filesystem');
my $folder = $namespace->subdir($cacher->{_key});
is($cacher->getFolder, $folder->stringify, 'getFolder returns the correct path, which is the namespace with a key subdirectory');
ok(! -e $cacher->getFolder, 'The folder does not exist in the filesystem');
$cacher->set('Some value');
ok( -e $namespace->stringify, 'setting data into the cache creates the namespace dir');
ok( -e $folder->stringify, 'setting data into the cache creates the folder dir');
ok( -e $folder->file('expires')->stringify, 'expiry file was created');
ok( -e $folder->file('cache')->stringify, 'cache file was created');
$cacher->delete();
ok(! -e $cacher->getFolder, 'delete removes the cache folder');
$cacher->flush();
ok(! -e $cacher->getNamespaceRoot, 'purge removes the namespace folder');
undef $cacher;
}
#----------------------------------------------------------------------------
# Cleanup
END {
$session->config->set('cacheType', $origCacheType);
if ($origCacheRoot) {
$session->config->get('fileCacheRoot', $origCacheRoot);
}
}