Skip to content

Commit

Permalink
Item9715: add 'askListeners' to the store, to support the store askin…
Browse files Browse the repository at this point in the history
…g a cache if it wants to serve a topic in preference to going back to the VC for it. Sort of experimental at the moment; comments invited.

git-svn-id: http://svn.foswiki.org/trunk@10216 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Dec 7, 2010
1 parent c770e6a commit 7efe76d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
23 changes: 23 additions & 0 deletions core/lib/Foswiki/Store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ sub tellListeners {

=begin TML
---++ ObjectMethod askListeners( $topicObject, $version )
Ask listeners if they would like to provide the object specified in the
$topicObject, at the given version. The first listener to respond with a
non-zero revision will be assumed to have loaded the topic object.
Listeners are expected to implement =loadTopic=. If they do not, they
will not be asked.
=cut

sub askListeners {
my ($this, $meta) = @_;
my ($gotRev, $isLatest);

foreach my $el (@{$this->{event_listeners}}) {
next unless $el->can('loadTopic');
($gotRev, $isLatest) = $el->loadTopic($meta);
return ($gotRev, $isLatest) if $gotRev;
}
}

=begin TML
---++ StaticMethod cleanUpRevID( $rev ) -> $integer
Cleans up (maps) a user-supplied revision ID and converts it to an integer
Expand Down
15 changes: 15 additions & 0 deletions core/lib/Foswiki/Store/Interfaces/Listener.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ a topic is moved.
---++ ObjectMethod remove($metaObject)
We are removing the given object.
---++ ObjectMethod loadTopic($meta, $version) -> ($gotRev, $isLatest)
Patterned on =Foswiki::Store::readTopic=, this listener is called when
the store's =readTopic= method is called. The first listener to return
a $meta will be assumed to have loaded that meta object with
the requested revision.
Implementors do *not* need to provide this method; it is called only if
it's present in the listener.
Note that the listener may re-bless the $meta into a subclass
of =Foswiki::Meta=, should it be necessary to enhance that class.
Listeners can also use this callback as a means of monitoring topic loads
from a VC store.
=cut

1;
Expand Down
8 changes: 5 additions & 3 deletions core/lib/Foswiki/Store/VC/Store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ sub getHandler {
sub readTopic {
my ( $this, $topicObject, $version ) = @_;

ASSERT( $topicObject->isa('Foswiki::Meta') ) if DEBUG;
my ($gotRev, $isLatest) = $this->askListeners($topicObject);
return ($gotRev, $isLatest) if $gotRev;

my $handler = $this->getHandler($topicObject);
my $isLatest = 0;
$isLatest = 0;

# check that the requested revision actually exists
if ( defined $version ) {
Expand All @@ -96,7 +98,7 @@ sub readTopic {
$text =~ s/\r//g; # Remove carriage returns
$topicObject->setEmbeddedStoreForm($text);

my $gotRev = $version;
$gotRev = $version;
unless ( defined $gotRev ) {

# First try the just-loaded text for the revision
Expand Down

0 comments on commit 7efe76d

Please sign in to comment.