Closed kmgdevelopment closed 6 months ago
👍 Also noticed this
For now I used 'cache' => App::devMode() ? false : 'PT1M',
, but haven't tested if this works in all cases
Same issue. Nothing helps even when cache is fully disabled. Only through ui when I clean the element-api cache or craft data-cache the response actually updates.
The weird thing is, the code is executed normally, and I see the updated data in the logs. But the response the browser receives is still the old one. Tested in Chrome and Firefox, both display the old reponse. devMode is also set.
return [
'defaults' => [
'elementType' => Entry::class,
'resourceKey' => 'elements',
'pretty' => Craft::$app->getConfig()->general->devMode,
'paginate' => false,
'cache' => false
],
'endpoints' => [
// ============================================================================================
// Globals
'globals' => function() {
if ($response = ApiHelper::assumeGet()) {
return $response;
}
Craft::warning('Globals requested');
$globals = GlobalSet::find()->all();
$result = new Item();
$result->setData($globals);
$r = rand(0, 1000);
$result->setTransformer(new GlobalTransformer($r));
Craft::$app->getResponse()->setNoCacheHeaders();
$r = $result->getTransformer()->transform($result->getData());
Craft::warning('Globals response' . print_r($r, true));
return $result;
},
/edit: maybe bit older version of the plugin: Craft edition & version Craft Pro 4.5.11.1 Yii version 2.0.48.1 Element API 3.0.1.1
Can anyone help on this?
You could set cache
dynamically based on whether Dev Mode is enabled:
'cache' => \craft\helpers\App::devMode(),
Description
I set up a simple endpoint that is outputting entry data as JSON, everything seems to be working correctly. The only problem is when I make a change to the endpoint in
config/element-api.php
and refresh the endpoint page, the changes are not automatically updated even though I havedevMode
enabled in my environment configuration. I've confirmed it isn't browser-side caching as I have tried manually clearing my browser cache. I have to manually go to Utilities > Caches > Invalidate Data Caches > Element API Responses in the control panel and clear the cache for the changes to show up.Obviously in a development environment this isn't ideal, and Element API shouldn't be caching in Dev Mode.
Here's my code:
Steps to reproduce
devMode
in environmentconfig/element-api.php
Additional info