zoho / zohocrm-php-sdk-6.0

Apache License 2.0
1 stars 1 forks source link

Local resources cache not updated when new choices added to custom field - check and refresh the cache #12

Closed rosskevin closed 3 weeks ago

rosskevin commented 3 weeks ago

When we add new choice values or change them in the CRM, deploy new code to our custom wordpress plugin, the old resources are used and the new choice values are not present/cause an exception as if we are passing invalid values.

If this SDK is going to cache values, it needs to be checking the equivalent of a last modified time to expire and refresh the cache.

rosskevin commented 3 weeks ago

I should note - I have deleted the resources folder locally, and my phpunit tests refreshed the cache and work.

On the other hand, I deleted the resources on the wordpress server, restarted the php engine, resources were regenerated (at least the a folder and file was created) but it still appears to have outdated values.

Server relevant log statements:

Pulling contacts settings:

2024-08-15 21:22:25 com\zoho\api\logger\SDKLogger INFO GET - URL = https://www.zohoapis.com/crm/v6/settings/fields?module=Contacts , headers = {"Authorization":" ## can't disclose ## ","X-ZOHO-SDK":"Linux\/5.4.0-1132-gcp\/php-6.0\/8.3.10:4.0.0"} , PARAMS = {"module":"Contacts"}.

Exception showing outdated choice values:

    [_message:com\zoho\crm\api\exception\SDKException:private] => {"field":"priority","class":"com\\zoho\\crm\\api\\record\\Record","index":0,"given-value":"MEC - Request for Demo","accepted-values":["-None-","Inquiry","Web Pricing Inquiry"]}

Why is a manual deletion of resources working locally but not in a server environment?

raja-7453 commented 3 weeks ago

@rosskevin Thank you for reaching out with your query.

The SDK caches field metadata to optimize performance. By default, the SDKConfig instance in the SDK is set with the autoRefreshFields parameter to false. This means that fields are not auto-refreshed in the background, and the SDK will use the cached metadata unless manually refreshed.

To address this, you can do either of the following two methods:

  1. Auto-Refresh: You can set autoRefreshFields to true, which will automatically refresh all module fields in the background every hour. This ensures that any changes made to choice values in the CRM are reflected in your plugin without manual intervention. If you need the fields refreshed before the hourly interval, consider manually refreshing the metadata using the second method.
  2. Manual Refresh/Deletion: Even with autoRefreshFields set to false, you can still manually delete the cached files or refresh the fields. This can be done using methods from ModuleFieldsHandler(com\zoho\crm\api\util\ModuleFieldsHandler).

Please refer to this help doc for more details.

Please let me know if this helps, or if you need further assistance please contact us at support@zohocrm.com.