Skip to content

Commit

Permalink
Add GeoJson caching
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Dec 3, 2018
1 parent cd9a90f commit c1ff874
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Maps_Settings.php
Expand Up @@ -165,6 +165,10 @@

// Other general configuration

// Integer. Determines the TTL of cached GeoJson.
// Default value: 0 (no caching).
$GLOBALS['egMapsGeoJsonCacheTtl'] = 0;

// Boolean. Sets if pages with maps should be put in special category
$GLOBALS['egMapsEnableCategory'] = false;

Expand Down
2 changes: 2 additions & 0 deletions src/DataAccess/CachingGeocoder.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace Maps\DataAccess;

use BagOStuff;
Expand Down
4 changes: 3 additions & 1 deletion src/DataAccess/JsonFileParser.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace Maps\DataAccess;

use FileFetcher\FileFetcher;
Expand All @@ -23,7 +25,7 @@ class JsonFileParser implements ValueParser {

public function __construct( $fileFetcher = null, PageContentFetcher $pageContentFetcher = null ) {
$this->fileFetcher = $fileFetcher instanceof FileFetcher
? $fileFetcher : MapsFactory::newDefault()->getFileFetcher();
? $fileFetcher : MapsFactory::newDefault()->getGeoJsonFileFetcher();

$this->pageContentFetcher = $pageContentFetcher instanceof PageContentFetcher
? $pageContentFetcher : MapsFactory::newDefault()->getPageContentFetcher();
Expand Down
2 changes: 2 additions & 0 deletions src/DataAccess/MapsFileFetcher.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace Maps\DataAccess;

use FileFetcher\FileFetcher;
Expand Down
2 changes: 2 additions & 0 deletions src/DataAccess/PageContentFetcher.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace Maps\DataAccess;

use MediaWiki\Storage\RevisionLookup;
Expand Down
17 changes: 17 additions & 0 deletions src/MapsFactory.php
Expand Up @@ -4,6 +4,7 @@

namespace Maps;

use FileFetcher\CachingFileFetcher;
use FileFetcher\FileFetcher;
use Jeroen\SimpleGeocoder\Geocoder;
use Jeroen\SimpleGeocoder\Geocoders\Decorators\CoordinateFriendlyGeocoder;
Expand All @@ -18,6 +19,8 @@
use Maps\Presentation\CoordinateFormatter;
use Maps\Presentation\WikitextParsers\LocationParser;
use MediaWiki\MediaWikiServices;
use SimpleCache\Cache\Cache;
use SimpleCache\Cache\MediaWikiCache;

/**
* @licence GNU GPL v2+
Expand Down Expand Up @@ -109,6 +112,20 @@ private function newFileFetcher(): FileFetcher {
return new MapsFileFetcher();
}

public function getGeoJsonFileFetcher(): FileFetcher {
return new CachingFileFetcher(
$this->getFileFetcher(),
$this->getMediaWikiSimpleCache( $this->settings['egMapsGeoJsonCacheTtl'] )
);
}

private function getMediaWikiSimpleCache( int $ttlInSeconds ): Cache {
return new MediaWikiCache(
$this->getMediaWikiCache(),
$ttlInSeconds
);
}

private function getMediaWikiCache(): \BagOStuff {
return wfGetCache( CACHE_ANYTHING );
}
Expand Down

0 comments on commit c1ff874

Please sign in to comment.