From 44e03d36e5e4297eaf66a907922ea931fc0118fa Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 27 Apr 2006 05:29:48 +0000 Subject: [PATCH] added database cache cleaner --- docs/upgrades/7fixup.pl | 2 + docs/upgrades/upgrade_6.8.8-6.99.0.pl | 7 +- etc/WebGUI.conf.original | 2 +- lib/WebGUI/Cache/Database.pm | 16 ++++ .../Workflow/Activity/CleanDatabaseCache.pm | 94 +++++++++++++++++++ .../Workflow_Activity_CleanDatabaseCache.pm | 30 ++++++ 6 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 lib/WebGUI/Workflow/Activity/CleanDatabaseCache.pm create mode 100644 lib/WebGUI/i18n/English/Workflow_Activity_CleanDatabaseCache.pm diff --git a/docs/upgrades/7fixup.pl b/docs/upgrades/7fixup.pl index 62a64346f..4eb106c70 100644 --- a/docs/upgrades/7fixup.pl +++ b/docs/upgrades/7fixup.pl @@ -41,6 +41,8 @@ sub addNewContent { groupIdEdit=>'4', description=>q|

The WebGUI Content Engine® is a powerful and easy to use system for managing web sites, and building web applications. It provides thousands of features out of the box, and lots of plug-in points so you can extend it to match your needs. It's easy enough for the average business user, but powerful enough for any large enterprise.

+

If you're new to WebGUI, click here to learn how to get started. If you're getting up to speed, check out some ways you can do more faster. If this is all old hat to you, then check out the latest news and tell your friends about WebGUI.

+

There are thousands of small and large businesses, schools, universities, governments, associations, clubs, churches, projects, and communities using WebGUI all over the world today. A brief list of some of them can be found here. Your site should be on that list.

|, templateId=>'PBtmpl0000000000000002' }); diff --git a/docs/upgrades/upgrade_6.8.8-6.99.0.pl b/docs/upgrades/upgrade_6.8.8-6.99.0.pl index fb04f687c..1773d7be0 100644 --- a/docs/upgrades/upgrade_6.8.8-6.99.0.pl +++ b/docs/upgrades/upgrade_6.8.8-6.99.0.pl @@ -420,7 +420,7 @@ sub addWorkflow { "WebGUI::Workflow::Activity::ExpireGroupings", "WebGUI::Workflow::Activity::PurgeOldAssetRevisions", "WebGUI::Workflow::Activity::ExpireSubscriptionCodes", "WebGUI::Workflow::Activity::PurgeOldTrash", "WebGUI::Workflow::Activity::GetSyndicatedContent", "WebGUI::Workflow::Activity::ProcessRecurringPayments", - "WebGUI::Workflow::Activity::SendQueuedMailMessages", + "WebGUI::Workflow::Activity::SendQueuedMailMessages", "WebGUI::Workflow::Activity::CleanDatabaseCache", "WebGUI::Workflow::Activity::SyncProfilesToLdap", "WebGUI::Workflow::Activity::SummarizePassiveProfileLog"], "WebGUI::User"=>["WebGUI::Workflow::Activity::CreateCronJob", "WebGUI::Workflow::Activity::NotifyAboutUser"], "WebGUI::VersionTag"=>["WebGUI::Workflow::Activity::CommitVersionTag", "WebGUI::Workflow::Activity::RollbackVersionTag", @@ -452,7 +452,10 @@ sub addWorkflow { $activity = $workflow->addActivity("WebGUI::Workflow::Activity::ProcessRecurringPayments", "pbwfactivity0000000013"); $activity->set("title", "Process Recurring Payments"); $activity = $workflow->addActivity("WebGUI::Workflow::Activity::CleanFileCache", "pbwfactivity0000000002"); - $activity->set("title","Prune cache larger than 100MB"); + $activity->set("title","Prune file cache larger than 100MB"); + $activity->set("sizeLimit", 1000000000); + $activity = $workflow->addActivity("WebGUI::Workflow::Activity::CleanDatabaseCache", "pbwfactivity0000000022"); + $activity->set("title","Prune database cache larger than 100MB"); $activity->set("sizeLimit", 1000000000); $activity = $workflow->addActivity("WebGUI::Workflow::Activity::ArchiveOldThreads", "pbwfactivity0000000005"); $activity->set("title", "Archive old CS threads"); diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index 49672ea08..2b6b7265d 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -311,7 +311,7 @@ "WebGUI::Workflow::Activity::ExpireSubscriptionCodes", "WebGUI::Workflow::Activity::PurgeOldTrash", "WebGUI::Workflow::Activity::GetSyndicatedContent", "WebGUI::Workflow::Activity::ProcessRecurringPayments", "WebGUI::Workflow::Activity::SyncProfilesToLdap", "WebGUI::Workflow::Activity::SummarizePassiveProfileLog", - "WebGUI::Workflow::Activity::SendQueuedMailMessages"], + "WebGUI::Workflow::Activity::SendQueuedMailMessages","WebGUI::Workflow::Activity::CleanDatabaseCache"], "WebGUI::User" : ["WebGUI::Workflow::Activity::CreateCronJob", "WebGUI::Workflow::Activity::NotifyAboutUser"], "WebGUI::VersionTag" : ["WebGUI::Workflow::Activity::CommitVersionTag", "WebGUI::Workflow::Activity::RollbackVersionTag", "WebGUI::Workflow::Activity::TrashVersionTag", "WebGUI::Workflow::Activity::CreateCronJob", diff --git a/lib/WebGUI/Cache/Database.pm b/lib/WebGUI/Cache/Database.pm index bbdde4fab..9cd71b91a 100644 --- a/lib/WebGUI/Cache/Database.pm +++ b/lib/WebGUI/Cache/Database.pm @@ -108,6 +108,22 @@ sub get { #------------------------------------------------------------------- +=head2 getNamespaceSize ( ) + +Returns the size (in bytes) of the current cache under this namespace. Consequently it also cleans up expired cache items. + +=cut + +sub getNamespaceSize { + my $self = shift; + my $expiresModifier = shift || 0; + $self->session->db->write("delete from cache where expires < ?",[time()+$expiresModifier]); + my ($size) = $self->session->db->quickArray("select sum(size) from cache where namepsace=?",[$self->{_namespace}]); + return $size; +} + +#------------------------------------------------------------------- + =head2 new ( session, key [, namespace ] ) Constructor. diff --git a/lib/WebGUI/Workflow/Activity/CleanDatabaseCache.pm b/lib/WebGUI/Workflow/Activity/CleanDatabaseCache.pm new file mode 100644 index 000000000..95e59e75d --- /dev/null +++ b/lib/WebGUI/Workflow/Activity/CleanDatabaseCache.pm @@ -0,0 +1,94 @@ +package WebGUI::Workflow::Activity::CleanDatabaseCache; + + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2006 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::defintion() 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("topicName"), + 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; + + diff --git a/lib/WebGUI/i18n/English/Workflow_Activity_CleanDatabaseCache.pm b/lib/WebGUI/i18n/English/Workflow_Activity_CleanDatabaseCache.pm new file mode 100644 index 000000000..e99eded68 --- /dev/null +++ b/lib/WebGUI/i18n/English/Workflow_Activity_CleanDatabaseCache.pm @@ -0,0 +1,30 @@ +package WebGUI::i18n::English::Workflow_Activity_CleanDatabaseCache; + +our $I18N = { + 'size limit help' => { + message => q|How big should WebGUI allow the cache to get before pruning down old cache entries?|, + context => q|the hover help for the cache field|, + lastUpdated => 0, + }, + + 'size limit' => { + message => q|Size Limit|, + context => q|a label indicating how big we're willing to allow the cache to get on this site|, + lastUpdated => 0, + }, + + 'bytes' => { + message => q|Bytes|, + context => q|The unit of measurement for the size limit field.|, + lastUpdated => 0, + }, + + 'topicName' => { + message => q|Clean Database Cache|, + context => q|The name of this workflow activity.|, + lastUpdated => 0, + }, + +}; + +1;