Please see this code first
public function setRefreshToken($token, $store = null) {
$scope = 'default';
$scopeId = 0;
if ($store !== null) {
$scope = 'stores';
$scopeId = $store->getId();
}
Mage::getConfig()->saveConfig('clougistic_twinfield/general/refresh_token', $token, $scope, $scopeId);
Mage::getConfig()->cleanCache();
}
This is magento 1 save config and clear cache code, here they save access token in config for further use and clear cache.
I have use this code for save config
/**
*
* @param MagentoFrameworkAppHelperContext $context
* @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
* @param MagentoFrameworkAppConfigStorageWriterInterface $configWriter
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkMessageManagerInterface $messageManager
* @param MagentoFrameworkAppState $state
*/
public function __construct(
MagentoFrameworkAppHelperContext $context,
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
MagentoFrameworkAppConfigStorageWriterInterface $configWriter,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoFrameworkAppState $state
){
$this->scopeConfig = $scopeConfig;
$this->messageManager = $messageManager;
$this->configWriter = $configWriter;
$this->cacheTypeList = $cacheTypeList;
$this->state = $state;
parent::__construct($context);
}
/**
* save token in config
*
* @param string $token
* @param object $store
* @return void
*/
public function setRefreshToken($token, $store = null)
{
$scope = 'default';
$scopeId = 0;
if ($store !== null) {
$scope = 'stores';
$scopeId = $store->getId();
}
$this->configWriter->save(self::TWINFIELD_CUSTOMER_REFERESH_TOKEN, $token, $scope, $scopeId);
$this->cacheTypeList->cleanType(MagentoFrameworkAppCacheTypeConfig::TYPE_IDENTIFIER);
}
it is working fine but it may affect on performance.
so if anyone have any better way to do this pleas share.
Thanks in advance.