PHP code example of acdh-oeaw / arche-diss-cache

1. Go to this page and download the library: Download acdh-oeaw/arche-diss-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

acdh-oeaw / arche-diss-cache example snippets



use Psr\Log\AbstractLogger;
use acdhOeaw\arche\lib\RepoResourceInterface;
use acdhOeaw\arche\lib\dissCache\Service;
use acdhOeaw\arche\lib\dissCache\ResponseCache;
use acdhOeaw\arche\lib\dissCache\ResponseCacheItem;
use acdhOeaw\arche\lib\dissCache\CallbackContextInterface;


class MyClass {
    static public method cacheHandler(
        RepositoryResourceInterface $res, 
        array $serveRequestParam,
        CallbackContextInterface $contextObj,
        object $config
    ){
        ...whatever needed...
        return new ResponseCacheItem($responseBody, $responseStatusCode, $responseHttpHeaders);
    }
}

$service = new Service('path_to_config.yaml');
$service->setCallback(fn($res, $param, $contextObj) => MyClass::cacheHandler($res, $param, $contextObj, $service->getConfig()));
$resId    = ...obtainResourceIdentifierFromTheRequest...;
$param    = [...readRequestParametersFromTheRequest...];
$response = $service->serveRequest($resId, $param);
$response->send();

// @var acdhOeaw\arche\lib\dissCache\CallbackContextInterface $context
$cache = $context->getFileCache();
$cache->getLog()

// @var acdhOeaw\arche\lib\dissCache\CallbackContextInterface $context
$cache = $context->getFileCache();
$pathToFile = $cache->getFileCache()->getResourceBinaryPath($res);