added database cache cleaner
This commit is contained in:
parent
cb29744bce
commit
44e03d36e5
6 changed files with 148 additions and 3 deletions
|
|
@ -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