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

Commit

Permalink
Fix Swagger caching issue, caused that Async Swagger and Usual Swagge…
Browse files Browse the repository at this point in the history
…r are using the same cache key
  • Loading branch information
nuzil committed Jan 4, 2019
1 parent 807ee7d commit dd1cdec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
21 changes: 19 additions & 2 deletions app/code/Magento/Webapi/Model/ServiceMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class ServiceMetadata
*/
private $serializer;

/**
* @var string
*/
private $routesConfigCacheId;

/**
* Initialize dependencies.
*
Expand All @@ -100,6 +105,7 @@ public function __construct(
$this->classReflector = $classReflector;
$this->typeProcessor = $typeProcessor;
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
$this->routesConfigCacheId = self::ROUTES_CONFIG_CACHE_ID;
}

/**
Expand Down Expand Up @@ -267,7 +273,7 @@ public function getRouteMetadata($serviceName)
public function getRoutesConfig()
{
if (null === $this->routes) {
$routesConfig = $this->cache->load(self::ROUTES_CONFIG_CACHE_ID);
$routesConfig = $this->cache->load($this->routesConfigCacheId);
$typesData = $this->cache->load(self::REFLECTED_TYPES_CACHE_ID);
if ($routesConfig && is_string($routesConfig) && $typesData && is_string($typesData)) {
$this->routes = $this->serializer->unserialize($routesConfig);
Expand All @@ -276,7 +282,7 @@ public function getRoutesConfig()
$this->routes = $this->initRoutesMetadata();
$this->cache->save(
$this->serializer->serialize($this->routes),
self::ROUTES_CONFIG_CACHE_ID
$this->routesConfigCacheId
);
$this->cache->save(
$this->serializer->serialize($this->typeProcessor->getTypesData()),
Expand All @@ -287,6 +293,17 @@ public function getRoutesConfig()
return $this->routes;
}

/**
* Set Routes Config Cache ID
*
* @param string $routesConfigCacheId
*/
public function setRoutesConfigCacheId($routesConfigCacheId){

$this->routesConfigCacheId = $routesConfigCacheId;

}

/**
* Collect the list of services with routes and request types for use in REST.
*
Expand Down
16 changes: 16 additions & 0 deletions app/code/Magento/WebapiAsync/Plugin/ServiceMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

class ServiceMetadata
{

const ASYNC_ROUTES_CONFIG_CACHE_ID = 'async-routes-services-config';

/**
* @var \Magento\Webapi\Model\Config
*/
Expand Down Expand Up @@ -272,4 +275,17 @@ private function getResponseDefinitionReplacement()

return $this->responseDefinitionReplacement;
}

/**
* Plugin to change config cache id for Asynchronous operations
*
* @return null
*/
public function beforeGetRoutesConfig(\Magento\Webapi\Model\ServiceMetadata $subject)
{
if ($this->asynchronousSchemaRequestProcessor->canProcess($this->request)) {
$subject->setRoutesConfigCacheId(self::ASYNC_ROUTES_CONFIG_CACHE_ID);
}
return null;
}
}

0 comments on commit dd1cdec

Please sign in to comment.