Expand my Community achievements bar.

SOLVED

Cache update rule

Avatar

Level 3

Hi ,

I have a custom component on page in which i am calling third party web service to pull the data. Requirement in this case is to serve the data from dispatcher cache every time user access the configured pages (cached data pulled from web service) but update the cache in regular intervals of time so that data is up-to date (update data/flush cache once in two hours for the pages that are configured with this specific component)

Could you please help me out in achieving this ?

Thanks,

Hari

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

you can trigger dispatcher invalidation whenever your webservice received new data. To achieve this, your code on publish needs to get the "Replicator" service and there use the "replicate" method and provide a custom agentFilter, which you can set in the ReplicationOptions. In teh agentFilter you can select which agent is actually triggered; in your case you need to select the "invalidate" agent (or whatever name this agent has on your system; instead of that you could also implement the selection based on the serialization type, which is a bit more code to write). See the API documentation for details.

kind regards,
Jörg

View solution in original post

8 Replies

Avatar

Correct answer by
Employee Advisor

Hi,

you can trigger dispatcher invalidation whenever your webservice received new data. To achieve this, your code on publish needs to get the "Replicator" service and there use the "replicate" method and provide a custom agentFilter, which you can set in the ReplicationOptions. In teh agentFilter you can select which agent is actually triggered; in your case you need to select the "invalidate" agent (or whatever name this agent has on your system; instead of that you could also implement the selection based on the serialization type, which is a bit more code to write). See the API documentation for details.

kind regards,
Jörg

Avatar

Community Advisor

I would suggest avoid caching the content on dispatcher and rather store webservice response under your repository, somewhere under /content or /etc.

For your component all the time reference point for data would be the repository location where you are storing the content and not webservice directly.

Now 2nd part is to regularly update the data in repository. For this requirement you can either use a scheduler OSGI service or Custom Importer, responsibility of these importer/scheduler would be to refresh the webservice content in repository.

With above approach even if your webservice goes down, still you will have reference data in repository to show on component.

-- Runal

Avatar

Level 10

Here are the Dispatcher config docs:

https://docs.adobe.com/docs/en/dispatcher/disp-config.html

I will get Dispatcher experts to look at this tomorrow if you need more help. 

Avatar

Level 3

Thanks for the config document,

I have looked into configurations but couldn't see any option to configure for my scenario/requirement. Could you please ask dispatcher experts to look into and suggest how i can achieve this either dispatcher rules or custom code ?

Thanks a lot for your help!

Avatar

Level 3

Hi ,

Thanks for your reply.

I got the point but what actually i am trying to avoid is calling web service every time on page hit. If we have to call invalidate on data change from web service- that means , we need to call web service on load of every page.

Please let me know your thoughts.

Thanks,

hari

Avatar

Employee Advisor

Hi,

you have 2 options here:

  • If the result of the webservice call does not change that often and is independent from the caller (e.g. a call to a weather service), you can do the webservice call periodically and run it by the Sling scheduler. Store the result in the repo, and when it changes, invalidate the cache afterwards.
  • If the result is either personalized or changes from call to call, caching doesn't make sense.

These are the options I see.

kind regards,
Jörg

Avatar

Level 2

One approach here would be to have a separate caching mechanism which will cache the web-service responses for you. The custom component can then look up to this cache for data before calling the web-service. You can explore the various caching technologies to check which best suit your need

Dispatcher is best used for caching the final html response from the content server rather than specific web-service responses used to build the html response.

Regards,

Kunal

Avatar

Level 3

Thanks a lot for information.

Web service data is independent of end user but it depends on page (data we pulled in component based on few parameters (which are inputs to web service call

))

Any thoughts ?