Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
storagecache.php
1<?php
2namespace Bitrix\Rest\OAuth;
3
4
7
9{
10 const CACHE_TTL = 3600;
11 const CACHE_PREFIX = "oauth_";
12
13 public function store(array $authResult)
14 {
15 $cache = $this->getCache();
16
17 $cache->read(static::CACHE_TTL, $this->getCacheId($authResult["access_token"]));
18 $cache->set($this->getCacheId($authResult["access_token"]), $authResult);
19 }
20
21 public function rewrite(array $authResult)
22 {
23 $cache = $this->getCache();
24
25 $cache->clean($this->getCacheId($authResult["access_token"]));
26 $cache->read(static::CACHE_TTL, $this->getCacheId($authResult["access_token"]));
27 $cache->set($this->getCacheId($authResult["access_token"]), $authResult);
28 }
29
30 public function restore($accessToken)
31 {
32 $cache = $this->getCache();
33
34 $authResult = false;
35
36 if($readResult = $cache->read(static::CACHE_TTL, $this->getCacheId($accessToken)))
37 {
38 $authResult = $cache->get($this->getCacheId($accessToken));
39 }
40
41 return $authResult;
42 }
43
44 protected function getCacheId($accessToken)
45 {
46 return static::CACHE_PREFIX.$accessToken;
47 }
48
49 protected function getCache()
50 {
51 return Application::getInstance()->getManagedCache();
52 }
53}