コード例 #1
0
 public static function hasCachedResponse(LinkedDataApiRequest $request)
 {
     if (!function_exists("memcache_connect")) {
         return false;
     }
     $acceptableTypes = $request->getAcceptTypes();
     $uri = $request->uri;
     foreach ($acceptableTypes as $mimetype) {
         $key = LinkedDataApiCache::cacheKey($uri, $mimetype);
         $mc = memcache_connect(PUELIA_MEMCACHE_HOST, PUELIA_MEMCACHE_PORT);
         $cachedObject = $mc->get($key);
         if ($cachedObject) {
             logDebug("Found a cached response for {$mimetype} under key {$key}");
             return $cachedObject;
         }
         logDebug("No cached response for {$mimetype} under key {$key}");
     }
     logDebug('No suitable cached responses found');
     return false;
 }
コード例 #2
0
ファイル: index.php プロジェクト: asavagar/EU-data-cloud
require 'deployment.settings.php';
require_once 'lda.inc.php';
require 'setup.php';
require_once 'lda-cache.class.php';
require_once 'lda-request.class.php';
require_once 'lda-response.class.php';
require_once 'graphs/configgraph.class.php';
require_once 'responses/Response304.class.php';
Logger::configure("puelia.logging.properties");
$HttpRequestFactory = new HttpRequestFactory();
if (function_exists('memcache_connect')) {
    $MemCacheObject = new LinkedDataApiCache();
    $HttpRequestFactory->set_cache($MemCacheObject);
}
$Request = new LinkedDataApiRequest();
header("Access-Control-Allow-Origin: *");
define("CONFIG_PATH", '/api-config');
define("CONFIG_URL", $Request->getBaseAndSubDir() . CONFIG_PATH);
logDebug("Request URI: " . $Request->getUri());
if (rtrim($Request->getPath(), '/') == $Request->getInstallSubDir()) {
    header("Location: " . CONFIG_URL, true, 303);
    exit;
}
if (defined("PUELIA_SERVE_FROM_CACHE") and !$Request->hasNoCacheHeader() and $cachedResponse = LinkedDataApiCache::hasCachedResponse($Request)) {
    logDebug("Found cached response");
    if (isset($Request->ifNoneMatch) && $cachedResponse->eTag == $Request->ifNoneMatch) {
        logDebug("ETag matched, returning 304");
        $Response = new Response304($cachedResponse);
    } else {
        if (isset($Request->ifModifiedSince) && $cachedResponse->generatedTime <= $Request->ifModifiedSince) {
コード例 #3
0
 public static function cacheResponse(LinkedDataApiRequest $request, LinkedDataApiResponse $response)
 {
     if (!function_exists("memcache_connect")) {
         return false;
     }
     $cacheableResponse = new LinkedDataApiCachedResponse();
     $cacheableResponse->eTag = $response->eTag;
     $cacheableResponse->generatedTime = $response->generatedTime;
     $cacheableResponse->lastModified = $response->lastModified;
     $cacheableResponse->mimetype = $response->mimetype;
     $cacheableResponse->body = $response->body;
     $key = LinkedDataApiCache::cacheKey($request->getOrderedUriWithoutApiKeys(), $cacheableResponse->mimetype);
     logDebug('Caching Response as ' . $key . ' with mimetype ' . $cacheableResponse->mimetype);
     $mc = memcache_connect(PUELIA_MEMCACHE_HOST, PUELIA_MEMCACHE_PORT);
     $mc->add($key, $cacheableResponse, false, PUELIA_CACHE_AGE);
 }