starting migration to memcached

This commit is contained in:
JT Smith 2009-09-24 23:28:45 -05:00
parent 66db563c39
commit 46737d6945
4 changed files with 22 additions and 222 deletions

View file

@ -18,6 +18,7 @@ BEGIN {
}
use strict;
use File::Path qw/rmtree/;
use Getopt::Long;
use WebGUI::Session;
use WebGUI::Storage;
@ -31,10 +32,31 @@ my $quiet; # this line required
my $session = start(); # this line required
moveMaintenance($session);
migrateToNewCache($session);
finish($session); # this line required
#----------------------------------------------------------------------------
sub migrateToNewCache {
my $session = shift;
print "\tMigrating to new cache " unless $quiet;
rmtree "../../lib/WebGUI/Cache";
unlink "../../lib/WebGUI/Workflow/Activity/CleanDatabaseCache.pm";
unlink "../../lib/WebGUI/Workflow/Activity/CleanFileCache.pm";
my $config = $session->config;
$config->set("cacheServers" => [ { "socket" => "/data/wre/var/memcached.sock", "host" => "127.0.0.1", "port" => "11211" } ]);
$config->delete("disableCache");
$config->delete("cacheType");
$config->delete("fileCacheRoot");
$config->deleteFromArray("workflowActivities/None", "WebGUI::Workflow::Activity::CleanDatabaseCache");
$config->deleteFromArray("workflowActivities/None", "WebGUI::Workflow::Activity::CleanFileCache");
my $db = $session->db;
$db->write("drop table cache");
$db->write("delete from WorkflowActivity where className in ('WebGUI::Workflow::Activity::CleanDatabaseCache','WebGUI::Workflow::Activity::CleanFileCache')");
print "DONE!\n" unless $quiet;
}
#----------------------------------------------------------------------------
sub moveMaintenance {
my $session = shift;

View file

@ -88,25 +88,6 @@
#"webServerPort" : 80,
# What kind of cache do you wish to use? Available types are
# WebGUI::Cache::FileCache and WebGUI::Cache::Database.
# We highly recommend the database cache if you are running
# sites with more than a few hundred pages, or if you're
# running in a multi-server environment. The file cache is better
# for very small sites.
"cacheType" : "WebGUI::Cache::FileCache",
# Tell WebGUI where to store cached files. Defaults to the
# /tmp or c:\temp folder depending upon your operating system.
# "fileCacheRoot" : "/path/to/cache",
# Set this to 1 to disable WebGUI's caching subsystems. This is
# mainly useful for developers.
"disableCache" : 0,
# The database connection string. It usually takes the form of
# DBI:<driver>:<db>;host:<hostname>
@ -857,8 +838,6 @@
"WebGUI::Workflow::Activity::ArchiveOldStories",
"WebGUI::Workflow::Activity::ArchiveOldThreads",
"WebGUI::Workflow::Activity::CalendarUpdateFeeds",
"WebGUI::Workflow::Activity::CleanDatabaseCache",
"WebGUI::Workflow::Activity::CleanFileCache",
"WebGUI::Workflow::Activity::CleanLoginHistory",
"WebGUI::Workflow::Activity::CleanTempStorage",
"WebGUI::Workflow::Activity::CreateCronJob",

View file

@ -1,94 +0,0 @@
package WebGUI::Workflow::Activity::CleanDatabaseCache;
=head1 LEGAL
-------------------------------------------------------------------
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
-------------------------------------------------------------------
=cut
use strict;
use base 'WebGUI::Workflow::Activity';
use WebGUI::Cache::Database;
=head1 NAME
Package WebGUI::Workflow::Activity::CleanDatabaseCache
=head1 DESCRIPTION
This activity deletes entries from the database cache if the cache size has gotten too big.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::definition() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "Workflow_Activity_CleanDatabaseCache");
push(@{$definition}, {
name=>$i18n->get("activityName"),
properties=> {
sizeLimit => {
fieldType=>"integer",
label=>$i18n->get("size limit"),
subtext=>$i18n->get("bytes"),
defaultValue=>100000000,
hoverHelp=>$i18n->get("size limit help")
}
}
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my $size = $self->get("sizeLimit") + 10;
my $expiresModifier = 0;
my $cache = WebGUI::Cache::Database->new($self->session);
while ($size > $self->get("sizeLimit")) {
$size = $cache->getNamespaceSize($expiresModifier);
$expiresModifier += 60 * 30; # add 30 minutes each pass
}
return $self->COMPLETE;
}
1;

View file

@ -1,107 +0,0 @@
package WebGUI::Workflow::Activity::CleanFileCache;
=head1 LEGAL
-------------------------------------------------------------------
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
-------------------------------------------------------------------
=cut
use strict;
use base 'WebGUI::Workflow::Activity';
use WebGUI::Cache::FileCache;
=head1 NAME
Package WebGUI::Workflow::Activity::CleanFileCache
=head1 DESCRIPTION
This activity deletes files from the file cache if the file cache has gotten too big.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::definition() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "Workflow_Activity_CleanFileCache");
push(@{$definition}, {
name=>$i18n->get("activityName"),
properties=> {
sizeLimit => {
fieldType=>"integer",
label=>$i18n->get("size limit"),
subtext=>$i18n->get("bytes"),
defaultValue=>100000000,
hoverHelp=>$i18n->get("size limit help")
}
}
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my $size = $self->get("sizeLimit") + 10;
my $expiresModifier = 0;
# Purge expired content cache
my $cache = WebGUI::Cache::FileCache->new($self->session);
while ($size > $self->get("sizeLimit")) {
$size = $cache->getNamespaceSize($expiresModifier);
$expiresModifier += 60 * 30; # add 30 minutes each pass
}
$size = $self->get("sizeLimit") + 10;
$expiresModifier = 0;
# Purge expired rss cache
my $rssCache = WebGUI::Cache::FileCache->new($self->session, undef, 'RSS');
while ($size > $self->get("sizeLimit")) {
$size = $rssCache->getNamespaceSize($expiresModifier);
$expiresModifier += 60 * 30; # add 30 minutes each pass
}
return $self->COMPLETE;
}
1;