Navigation Menu

Skip to content

Commit

Permalink
Item14500: add REST handler for cache maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Sep 25, 2017
1 parent 7f24702 commit 5b3537f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
3 changes: 2 additions & 1 deletion data/System/OEmbedPlugin.txt
Expand Up @@ -231,6 +231,7 @@ See the =oembed.tmpl= file on how to use them.
%$DEPENDENCIES%

---++ Change History
| 25 Sep 2017 | added =clearCache= REST interface for local cache maintenance |
| 17 Nov 2016 | more providers; converted Web::oEmbed from Any::Moose to Moo |
| 07 Oct 2015 | multiple providers went in & out |
| 16 Mar 2015 | added Infogram |
Expand All @@ -249,7 +250,7 @@ See the =oembed.tmpl= file on how to use them.

%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Michael Daum"}%
%META:FIELD{name="Copyright" title="Copyright" value="© 2013-2016 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Copyright" title="Copyright" value="© 2013-2017 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/%TOPIC%"}%
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
Expand Down
14 changes: 9 additions & 5 deletions lib/Foswiki/Plugins/OEmbedPlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# OEmbedPlugin is Copyright (C) 2013-2016 Michael Daum http://michaeldaumconsulting.com
# OEmbedPlugin is Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -20,8 +20,8 @@ use warnings;

use Foswiki::Func ();

our $VERSION = '5.30';
our $RELEASE = '17 Nov 2016';
our $VERSION = '5.41';
our $RELEASE = '25 Sep 2017';
our $SHORTDESCRIPTION = 'Easy embedding of third party content';
our $NO_PREFS_IN_TOPIC = 1;
our $core;
Expand All @@ -39,6 +39,12 @@ sub initPlugin {
http_allow => 'GET,POST',
);

Foswiki::Func::registerRESTHandler('clearCache', sub { return getCore()->clearCache(@_); },
authenticate => 0,
validate => 0,
http_allow => 'GET,POST',
);

Foswiki::Func::registerRESTHandler('provider', sub { return getCore()->provider(@_); },
authenticate => 0,
validate => 0,
Expand All @@ -58,6 +64,4 @@ sub getCore {
return $core;
}



1;
3 changes: 3 additions & 0 deletions lib/Foswiki/Plugins/OEmbedPlugin/Config.spec
Expand Up @@ -7,6 +7,9 @@
# Otherwise embed.ly providers won't be available.
$Foswiki::cfg{OEmbedPlugin}{EmbedlyKey} = '';

# **NUMBER**
$Foswiki::cfg{OEmbedPlugin}{CacheExpire} = 3600;

# **PERL**
# List of providers and their oEmbed API endpoints.
# See http://oembed.com/ and http://embed.ly for more.
Expand Down
14 changes: 11 additions & 3 deletions lib/Foswiki/Plugins/OEmbedPlugin/Consumer.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# OEmbedPlugin is Copyright (C) 2013-2016 Michael Daum http://michaeldaumconsulting.com
# OEmbedPlugin is Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -46,13 +46,15 @@ sub embed {

my $res = $cache->get($key);

if ($res) {
if (defined $res) {
$res = Storable::thaw($res);
} else {
$res = $this->agent->get($url);
$cache->set($key, Storable::freeze($res));
my $frozen = Storable::freeze($res) if defined $res;
$cache->set($key, $frozen) if defined $frozen;
}

return unless defined $res;
return Web::oEmbed::Response->new_from_response($res, $uri);
}

Expand Down Expand Up @@ -83,6 +85,12 @@ sub purgeCache {
$this->_cache->purge;
}

sub clearCache {
my $this = shift;

$this->_cache->clear;
}

sub _cache {
my $this = shift;

Expand Down
11 changes: 9 additions & 2 deletions lib/Foswiki/Plugins/OEmbedPlugin/Core.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# OEmbedPlugin is Copyright (C) 2013-2016 Michael Daum http://michaeldaumconsulting.com
# OEmbedPlugin is Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -150,11 +150,12 @@ sub EMBED {

if ($@) {
print STDERR "ERROR: $@\n" if $warn;
return "<span class='foswikiAlert'>ERROR: $@</span>" if $warn;
}

unless (defined $response) {
writeDebug("no response for $url");
return $url;
return "<span class='foswikiAlert'>no response from url</span>" if $warn;
}

$response->web_page($url); # SMELL: hook in the orig url
Expand Down Expand Up @@ -256,4 +257,10 @@ sub purgeCache {
$this->{consumer}->purgeCache;
}

sub clearCache {
my $this = shift;

$this->{consumer}->clearCache;
}

1;
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/OEmbedPlugin/MANIFEST
@@ -1,3 +1,4 @@
!noci
data/System/OEmbedPlugin.txt 0644
lib/CPAN/lib/Regexp/Assemble.pm 0644
lib/Foswiki/Plugins/OEmbedPlugin/Config.spec 0644
Expand Down

0 comments on commit 5b3537f

Please sign in to comment.