diff --git a/_config/config.yml b/_config/config.yml new file mode 100644 index 0000000..6c9ca7e --- /dev/null +++ b/_config/config.yml @@ -0,0 +1,9 @@ +SilverStripe\Core\Injector\Injector: + Psr\SimpleCache\CacheInterface.OP: + factory: SilverStripe\Core\Cache\CacheFactory + constructor: + namespace: 'OP' + defaultLifetime: 3600 + backend: 'Filesystem' + disable-container: true + directory: 'assets/jsoncache' \ No newline at end of file diff --git a/code/CRM.php b/code/CRM.php index b171729..442d293 100644 --- a/code/CRM.php +++ b/code/CRM.php @@ -10,8 +10,8 @@ use Exception; use Fiber; use Psr\Log\LoggerInterface; +use Psr\SimpleCache\CacheInterface; use SilverStripe\Core\Injector\Injector; -use Symfony\Component\Cache\Simple\FilesystemCache; use SilverStripe\Dev\Debug; class CRM @@ -37,8 +37,7 @@ class CRM */ public function __construct() { - - $cache = new FilesystemCache('OP'); + $cache = Injector::inst()->get(CacheInterface::class . '.OP'); if ($cache->has($this->getCacheKey())) { $this->access_token = $cache->get($this->getCacheKey()); @@ -87,8 +86,7 @@ protected function CreateTokenHTTPQuery() * * @return string */ - public function getResourceURL() - { + public function getResourceURL() { return Environment::getEnv('AZUREAPPLICATIONRESOURCELOCATION'); } @@ -131,7 +129,7 @@ private function RequestAccessToken() // set the cache and the time to live according to the result if (isset($content->expires_in)) { - $cache = new FilesystemCache('OP'); + $cache = Injector::inst()->get(CacheInterface::class . '.OP'); $this->access_token = $cache->set($this->getCacheKey(), $content->access_token, (int) $content->expires_in); } @@ -176,7 +174,7 @@ public function fetch($webservice_url_str, $method = "GET", $postdata = null, $e // return data and try for 5 seconds curl_setopt($session, CURLOPT_RETURNTRANSFER, true); curl_setopt($session, CURLOPT_CONNECTTIMEOUT, 5); - // curl_setopt($session, CURLOPT_VERBOSE, 1); + // curl_setopt($session, CURLOPT_VERBOSE, 1); curl_setopt($session, CURLOPT_HEADER, 1); //CWP proxy stuff diff --git a/readme.md b/readme.md index 0054aa5..9cd023f 100644 --- a/readme.md +++ b/readme.md @@ -69,6 +69,9 @@ sendBatchRequest sends requests using cURL in a Fiber for asynchronous execution ![Step 6](images/azure4.png) 7. You should now have everything you need to use the CRM module. +# don't forget to use .htaccess to block the cache if you store it in your assets folder +RedirectMatch 404 ^/assets/jsoncache/.*$ + # Using the Envornment version: ==================