Skip to content

Commit

Permalink
SS5 cache support
Browse files Browse the repository at this point in the history
  • Loading branch information
torleif committed Aug 7, 2024
1 parent 81c2f5e commit a0cdb99
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
9 changes: 9 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -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'
12 changes: 5 additions & 7 deletions code/CRM.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand Down Expand Up @@ -87,8 +86,7 @@ protected function CreateTokenHTTPQuery()
*
* @return string
*/
public function getResourceURL()
{
public function getResourceURL() {
return Environment::getEnv('AZUREAPPLICATIONRESOURCELOCATION');
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
==================

Expand Down

0 comments on commit a0cdb99

Please sign in to comment.