Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit dd1cdec

Browse files
committed
Fix Swagger caching issue, caused that Async Swagger and Usual Swagger are using the same cache key
1 parent 807ee7d commit dd1cdec

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

app/code/Magento/Webapi/Model/ServiceMetadata.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ class ServiceMetadata
7979
*/
8080
private $serializer;
8181

82+
/**
83+
* @var string
84+
*/
85+
private $routesConfigCacheId;
86+
8287
/**
8388
* Initialize dependencies.
8489
*
@@ -100,6 +105,7 @@ public function __construct(
100105
$this->classReflector = $classReflector;
101106
$this->typeProcessor = $typeProcessor;
102107
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
108+
$this->routesConfigCacheId = self::ROUTES_CONFIG_CACHE_ID;
103109
}
104110

105111
/**
@@ -267,7 +273,7 @@ public function getRouteMetadata($serviceName)
267273
public function getRoutesConfig()
268274
{
269275
if (null === $this->routes) {
270-
$routesConfig = $this->cache->load(self::ROUTES_CONFIG_CACHE_ID);
276+
$routesConfig = $this->cache->load($this->routesConfigCacheId);
271277
$typesData = $this->cache->load(self::REFLECTED_TYPES_CACHE_ID);
272278
if ($routesConfig && is_string($routesConfig) && $typesData && is_string($typesData)) {
273279
$this->routes = $this->serializer->unserialize($routesConfig);
@@ -276,7 +282,7 @@ public function getRoutesConfig()
276282
$this->routes = $this->initRoutesMetadata();
277283
$this->cache->save(
278284
$this->serializer->serialize($this->routes),
279-
self::ROUTES_CONFIG_CACHE_ID
285+
$this->routesConfigCacheId
280286
);
281287
$this->cache->save(
282288
$this->serializer->serialize($this->typeProcessor->getTypesData()),
@@ -287,6 +293,17 @@ public function getRoutesConfig()
287293
return $this->routes;
288294
}
289295

296+
/**
297+
* Set Routes Config Cache ID
298+
*
299+
* @param string $routesConfigCacheId
300+
*/
301+
public function setRoutesConfigCacheId($routesConfigCacheId){
302+
303+
$this->routesConfigCacheId = $routesConfigCacheId;
304+
305+
}
306+
290307
/**
291308
* Collect the list of services with routes and request types for use in REST.
292309
*

app/code/Magento/WebapiAsync/Plugin/ServiceMetadata.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
class ServiceMetadata
1717
{
18+
19+
const ASYNC_ROUTES_CONFIG_CACHE_ID = 'async-routes-services-config';
20+
1821
/**
1922
* @var \Magento\Webapi\Model\Config
2023
*/
@@ -272,4 +275,17 @@ private function getResponseDefinitionReplacement()
272275

273276
return $this->responseDefinitionReplacement;
274277
}
278+
279+
/**
280+
* Plugin to change config cache id for Asynchronous operations
281+
*
282+
* @return null
283+
*/
284+
public function beforeGetRoutesConfig(\Magento\Webapi\Model\ServiceMetadata $subject)
285+
{
286+
if ($this->asynchronousSchemaRequestProcessor->canProcess($this->request)) {
287+
$subject->setRoutesConfigCacheId(self::ASYNC_ROUTES_CONFIG_CACHE_ID);
288+
}
289+
return null;
290+
}
275291
}

0 commit comments

Comments
 (0)