[Mapbender-commits] r9218 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Jun 19 04:48:22 PDT 2015
Author: armin11
Date: 2015-06-19 04:48:22 -0700 (Fri, 19 Jun 2015)
New Revision: 9218
Modified:
trunk/mapbender/http/classes/class_administration.php
trunk/mapbender/http/classes/class_cache.php
trunk/mapbender/http/classes/class_metadata_new.php
Log:
store wmc to apc cache on demand
Modified: trunk/mapbender/http/classes/class_administration.php
===================================================================
--- trunk/mapbender/http/classes/class_administration.php 2015-06-19 11:42:40 UTC (rev 9217)
+++ trunk/mapbender/http/classes/class_administration.php 2015-06-19 11:48:22 UTC (rev 9218)
@@ -1692,6 +1692,117 @@
+ function putToStorage($filename, $content, $cacheType, $maxAge) {
+ switch ($cacheType) {
+ case "memcache":
+ $filename = md5($filename);
+ $memcache_obj = new Memcache;
+ if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+ $memcache_obj->connect(MEMCACHED_IP, MEMCACHED_PORT);
+ } else {
+ //use standard options
+ $memcache_obj->connect('localhost', 11211);
+ }
+ //check for existence
+ $objectExists = $memcache_obj->get($filename);
+
+ if ($objectExists == false) {
+ $memcache_obj->add($filename, $content, false, $maxAge);
+ new mb_notice("add object");
+ } else {
+ $memcache_obj->replace($filename, $content, false, $maxAge);
+ new mb_notice("replace object");
+ }
+ $memcache_obj->close();
+ return true;
+ break;
+ case "memcached":
+ $filename = md5($filename);
+ $memcached_obj = new Memcached;
+ if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+ $memcached_obj->addServer(MEMCACHED_IP, MEMCACHED_PORT);
+ } else {
+ //use standard options
+ $memcached_obj->addServer('localhost', 11211);
+ }
+ new mb_notice("file stored via memcacheD");
+
+ $memcached_obj->set($filename, $content, $maxAge);
+ //$memcached_obj->quit();
+ return true;
+ break;
+ case "cache":
+ $filename = md5($filename);
+ $cache = new Cache();
+ if ($cache->isActive) {
+ if ($cache->cachedVariableExists($filename)) {
+ $cache->cachedVariableDelete($filename);
+ }
+ return $cache->cachedVariableAdd($filename, $content ,$maxAge);
+ } else {
+ return false;
+ }
+ break;
+ case "file":
+ file_put_contents($filename, $content);
+ break;
+ default:
+ file_put_contents($filename, $content);
+ break;
+ }
+ }
+
+ function getFromStorage($filename, $cacheType) {
+ switch ($cacheType) {
+ case "memcache":
+ $filename = md5($filename);
+ $memcache_obj = new Memcache;
+ if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+ $memcache_obj->connect(MEMCACHED_IP, MEMCACHED_PORT);
+ } else {
+ //use standard options
+ $memcache_obj->connect('localhost', 11211);
+ }
+ $content = $memcache_obj->get($filename);
+ $memcache_obj->close();
+ return $content;
+ break;
+ case "memcached":
+ $filename = md5($filename);
+ $memcached_obj = new Memcached;
+ if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+ $memcached_obj->addServer(MEMCACHED_IP, MEMCACHED_PORT);
+ } else {
+ //use standard options
+ $memcached_obj->addServer('localhost', 11211);
+ }
+ new mb_notice("content via memcacheD");
+ $content = $memcached_obj->get($filename);
+ //$memcached_obj->quit();
+ return $content;
+ break;
+ case "cache":
+ $filename = md5($filename);
+ $cache = new Cache();
+ if ($cache->isActive && $cache->cachedVariableExists($filename)) {
+ $content = $cache->cachedVariableFetch($filename);
+ return $content;
+ } else {
+ return false;
+ }
+ break;
+ case "file":
+ $content = file_get_contents($filename);
+ return $content;
+ break;
+ default:
+ $content = file_get_contents($filename);
+ return $content;
+ break;
+ }
+ }
+
+
Modified: trunk/mapbender/http/classes/class_cache.php
===================================================================
--- trunk/mapbender/http/classes/class_cache.php 2015-06-19 11:42:40 UTC (rev 9217)
+++ trunk/mapbender/http/classes/class_cache.php 2015-06-19 11:48:22 UTC (rev 9218)
@@ -94,10 +94,10 @@
return false;
}
- final public function cachedVariableAdd($key, $value) {
+ final public function cachedVariableAdd($key, $value, $ttl = 0) {
switch ($this->cacheType) {
case "apc":
- return apc_add($key, $value);
+ return apc_add($key, $value, $ttl);
break;
default:
return false;
Modified: trunk/mapbender/http/classes/class_metadata_new.php
===================================================================
--- trunk/mapbender/http/classes/class_metadata_new.php 2015-06-19 11:42:40 UTC (rev 9217)
+++ trunk/mapbender/http/classes/class_metadata_new.php 2015-06-19 11:48:22 UTC (rev 9218)
@@ -60,7 +60,7 @@
var $hostName;
var $resourceIds;
var $restrictToOpenData;
- var $originFromHeader;
+ var $originFromHeader;
function __construct($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources, $searchPages, $outputFormat, $resultTarget, $searchURL, $customCategories, $hostName, $orderBy, $resourceIds, $restrictToOpenData, $originFromHeader){
$this->userId = (integer)$userId;
@@ -101,7 +101,13 @@
$this->maxWeight = 0;
$this->scale = 'linear';
$this->minFontSize = 10;
- $this->tempFolder = TMPDIR; //TODO define another path - maybe the one which is given in mapbender.conf
+
+ if (defined("ABSOLUTE_TMPDIR")){
+ $this->tempFolder = ABSOLUTE_TMPDIR;
+ } else {
+ $this->tempFolder = TMPDIR;
+ }
+
if ($this->outputFormat == 'json'){
$this->json = new Mapbender_JSON;
}
@@ -820,10 +826,14 @@
$this->wmsJSON->wms->md->genTime = $usedTime;
$this->wmsJSON = $this->json->encode($this->wmsJSON);
if ($this->resultTarget == 'file') {
- if($wmsFileHandle = fopen($this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json","w")){
+ //$e = new mb_exception("write wms to file: ".$wmsJSONString);
+ $filename = $this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json";
+ $admin = new administration();
+ $admin->putToStorage($filename, $this->wmsJSON, TMP_SEARCH_RESULT_STORAGE, TMP_SEARCH_RESULT_MAX_AGE);
+ /*if($wmsFileHandle = fopen($this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json","w")){
fwrite($wmsFileHandle,$this->wmsJSON);
fclose($wmsFileHandle);
- }
+ }*/
}
if ($this->resultTarget == 'web' or $this->resultTarget == 'debug') {
echo $this->wmsJSON;
@@ -874,10 +884,14 @@
$this->wfsJSON->wfs->md->genTime = $usedTime;
$this->wfsJSON = $this->json->encode($this->wfsJSON);
if ($this->resultTarget == 'file') {
- if($wfsFileHandle = fopen($this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json","w")){
+ $filename = $this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json";
+ $admin = new administration();
+ $admin->putToStorage($filename, $this->wfsJSON, TMP_SEARCH_RESULT_STORAGE, TMP_WMC_MAX_AGE);
+
+ /*if($wfsFileHandle = fopen($this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json","w")){
fwrite($wfsFileHandle,$this->wfsJSON);
fclose($wfsFileHandle);
- }
+ }*/
}
if ($this->resultTarget == 'web'or $this->resultTarget == 'debug') {
echo $this->wfsJSON;
@@ -900,10 +914,13 @@
$this->wmcJSON->wmc->md->genTime = $usedTime;
$this->wmcJSON = $this->json->encode($this->wmcJSON);
if ($this->resultTarget == 'file') {
- if($wmcFileHandle = fopen($this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json","w")){
+ $filename = $this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json";
+ $admin = new administration();
+ $admin->putToStorage($filename, $this->wmcJSON, TMP_SEARCH_RESULT_STORAGE, TMP_SEARCH_RESULT_MAX_AGE);
+ /*if($wmcFileHandle = fopen($this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json","w")){
fwrite($wmcFileHandle,$this->wmcJSON);
fclose($wmcFileHandle);
- }
+ }*/
}
if ($this->resultTarget == 'web' or $this->resultTarget == 'debug') {
echo $this->wmcJSON;
@@ -928,10 +945,13 @@
$this->datasetJSON->dataset->md->genTime = $usedTime;
$this->datasetJSON = $this->json->encode($this->datasetJSON);
if ($this->resultTarget == 'file') {
- if($datasetFileHandle = fopen($this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json","w")){
+ $filename = $this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json";
+ $admin = new administration();
+ $admin->putToStorage($filename, $this->datasetJSON, TMP_SEARCH_RESULT_STORAGE, TMP_SEARCH_RESULT_MAX_AGE);
+ /*if($datasetFileHandle = fopen($this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json","w")){
fwrite($datasetFileHandle,$this->datasetJSON);
fclose($datasetFileHandle);
- }
+ }*/
}
if ($this->resultTarget == 'web' or $this->resultTarget == 'debug') {
echo $this->datasetJSON;
@@ -1283,13 +1303,15 @@
//encode json!
$this->keyJSON = $this->json->encode($this->keyJSON);
//write clouds to file
- if($keyFileHandle = fopen($keyFilename, "w")){
+ $admin = new administration();
+ $admin->putToStorage($keyFilename, $this->keyJSON, TMP_SEARCH_RESULT_STORAGE, TMP_SEARCH_RESULT_MAX_AGE);
+ /*if($keyFileHandle = fopen($keyFilename, "w")){
fwrite($keyFileHandle,$this->keyJSON);
fclose($keyFileHandle);
$e = new mb_notice("class_metadata: new ".$this->searchResources."_keyword_file created!");
} else {
$e = new mb_notice("class_metadata: cannot create ".$this->searchResources."_keyword_file!");
- }
+ }*/
if ($this->resultTarget == 'debug') {
echo "<br>DEBUG: show keywords: <br>".$this->keyJSON."<br><br>";
}
@@ -1387,13 +1409,16 @@
$this->catJSON = $this->json->encode($this->catJSON);
//write categories files only when file is requested and the searchid was not used before!
if ($this->resultTarget == 'file') {
- if($catFileHandle = fopen($filename, "w")){
+ //$filename = $this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json";
+ $admin = new administration();
+ $admin->putToStorage($filename, $this->catJSON, TMP_SEARCH_RESULT_STORAGE, TMP_SEARCH_RESULT_MAX_AGE);
+ /*if($catFileHandle = fopen($filename, "w")){
fwrite($catFileHandle,$this->catJSON);
fclose($catFileHandle);
$e = new mb_notice("class_metadata: new ".$this->searchResources."_class_file created!");
} else {
$e = new mb_notice("class_metadata: cannot create ".$this->searchResources."_cat_file!");
- }
+ }*/
}
if ($this->resultTarget == 'debug') {
@@ -1416,8 +1441,8 @@
//TODO: Set Email of owner into view for ressource - so it don't have to be searched?
$return_permission = "";
//get permission
- $admin = new administration();
- $myWFSconfs = $admin->getWfsConfByPermission($this->userId);
+ //$admin = new administration();
+ $myWFSconfs = $this->admin->getWfsConfByPermission($this->userId);
$this->myWFSConfs = $myWFSconfs;
for ($index = 0; $index < sizeof($this->myWFSConfs); $index++) {
$array_element = $this->myWFSConfs[$index];
More information about the Mapbender_commits
mailing list