added database cache cleaner
This commit is contained in:
parent
cb29744bce
commit
44e03d36e5
6 changed files with 148 additions and 3 deletions
|
|
@ -41,6 +41,8 @@ sub addNewContent {
|
|||
groupIdEdit=>'4',
|
||||
description=>q|<p>The <a href="http://www.webgui.org">WebGUI Content Engine®</a> 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.</p>
|
||||
|
||||
<p>If you're new to WebGUI, <a href="^/;getting_started">click here to learn how to get started</a>. If you're getting up to speed, <a href="^/;your_next_step">check out some ways you can do more faster</a>. If this is all old hat to you, then check out <a href="^/;the_latest_news">the latest news</a> and <a href="^/;tell_a_friend">tell your friends</a> about WebGUI.</p>
|
||||
|
||||
<p>There are thousands of <a href="http://www.jeffmillerphotography.com">small</a> and <a href="http://www.brunswicknt.com">large</a> businesses, <a href="http://phila.k12.pa.us">schools</a>, <a href="http://www.csumathsuccess.org">universities</a>, <a href="http://beijing.usembassy.gov/">governments</a>, <a href="http://www.gama.org">associations</a>, <a href="http://www.monashwushu.com">clubs</a>, <a href="http://www.sunsetpres.org">churches</a>, <a href="http://www.k3b.org">projects</a>, and <a href="http://www.comparehangouts.com">communities</a> using WebGUI all over the world today. A brief list of some of them can be found <a href="http://www.plainblack.com/webgui/campaigns/sightings">here</a>. Your site should be on that list.</p>|,
|
||||
templateId=>'PBtmpl0000000000000002'
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
94
lib/WebGUI/Workflow/Activity/CleanDatabaseCache.pm
Normal file
94
lib/WebGUI/Workflow/Activity/CleanDatabaseCache.pm
Normal file
|
|
@ -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;
|
||||
|
||||
|
||||
|
|
@ -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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue