Invalidation is not happening while triggerring the flush request for custom servlet through code | Community
Skip to main content
Level 2
March 1, 2024
Solved

Invalidation is not happening while triggerring the flush request for custom servlet through code

  • March 1, 2024
  • 2 replies
  • 1268 views

We have cached country specific custom servlets(e.g  /bin/myproject/servlet/us/en/myservlet.json) at the dispatcher in JSON format. When a XF is replicated, we need to clear cached JSON files for all countries. So we are triggering resource-only-flush request for /bin/myproject/servlet.

 

From Publish logs, could confirm that the flush request is successful.

 

com.day.cq.replication.Agent.resource-only-flush ------------------------------------------------
com.day.cq.replication.Agent.resource-only-flush Sending message to dispatcher:8080
com.day.cq.replication.Agent.resource-only-flush >> POST /dispatcher/invalidate.cache HTTP/1.0
com.day.cq.replication.Agent.resource-only-flush >> CQ-Action: Activate
com.day.cq.replication.Agent.resource-only-flush >> CQ-Handle: /bin/myproject/servlet
com.day.cq.replication.Agent.resource-only-flush >> CQ-Path: /bin/myproject/servlet
com.day.cq.replication.Agent.resource-only-flush >> CQ-Action-Scope: ResourceOnly
com.day.cq.replication.Agent.resource-only-flush >> Referer: about:blank
com.day.cq.replication.Agent.resource-only-flush >> Content-Length: 0
com.day.cq.replication.Agent.resource-only-flush >> Content-Type: application/octet-stream
com.day.cq.replication.Agent.resource-only-flush --
com.day.cq.replication.Agent.resource-only-flush << HTTP/1.1 200 OK
com.day.cq.replication.Agent.resource-only-flush << Date: Fri, 01 Mar 2024 10:10:10 GMT
com.day.cq.replication.Agent.resource-only-flush << Server: Apache/2.4.20 (Unix) OpenSSL/1.0.2h Communique/4.1.12
com.day.cq.replication.Agent.resource-only-flush << Cache-Control: max-age=0
com.day.cq.replication.Agent.resource-only-flush << Expires: Fri, 01 Mar 2024 10:10:10 GMT
com.day.cq.replication.Agent.resource-only-flush << Vary: User-Agent
com.day.cq.replication.Agent.resource-only-flush << Content-Length: 13
com.day.cq.replication.Agent.resource-only-flush << Content-Type: text/html; charset=utf-8
com.day.cq.replication.Agent.resource-only-flush <<
com.day.cq.replication.Agent.resource-only-flush <<
com.day.cq.replication.Agent.resource-only-flush Message sent.
com.day.cq.replication.Agent.resource-only-flush ------------------------------------------------
com.day.cq.replication.Agent.resource-only-flush Replication (ACTIVATE) of /bin/myproject/servlet successful.

 

Also from dispatcher logs, could confirm that the invalidation request is received

 

[Fri Mar 01 11:10:10 2024] [D] [75912] checking [/dispatcher/invalidate.cache]
[Fri Mar 01 11:10:10 2024] [I] [75912] Activation detected: action=Activate [/bin/myproject/servlet]
[Fri Mar 01 11:10:10 2024] [D] [75912] response.status = 200
[Fri Mar 01 11:10:10 2024] [D] [75912] response.headers[Server] = "Communique/2.6.3 (build 5221)"
[Fri Mar 01 11:10:10 2024] [D] [75912] response.headers[Content-Type] = "text/html"
[Fri Mar 01 11:10:10 2024] [D] [75912] cache flushed

 

But the servlet folder /bin/myproject/servlet is not cleared at Dispatcher cache location.

 

Any suggestions on what is missing here?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Raja_Reddy

Hi @sriabinaya_subramani 

Based on the logs you provided, it seems that the resource-only-flush request was successful and the invalidation request was received by the dispatcher. However, it's possible that the cached JSON files for all countries were not cleared because the invalidation request was not specific enough.

When you trigger a resource-only-flush request for `/bin/myproject/servlet`, it invalidates the cache for that specific path only. It does not invalidate the cache for any child paths or any other paths that may be related to the servlet.

To clear the cached JSON files for all countries, you may need to trigger a resource-only-flush request for each country-specific path, such as `/bin/myproject/servlet/us/en/myservlet.json`, `/bin/myproject/servlet/uk/en/myservlet.json`, etc. This will ensure that the cache for each country-specific path is cleared and the updated JSON files are served from the publish instance.

Alternatively, you can trigger a full cache flush on the dispatcher to clear all cached content. However, this may not be desirable if you have a large amount of cached content or if you want to minimize the impact on the dispatcher performance.

Thanks,
Raja

2 replies

SureshDhulipudi
Community Advisor
Community Advisor
March 1, 2024

how do you configure the cache rule to cache the servlet and what the servlet response headers - can you please provide the details

Level 2
March 1, 2024

Hi @sureshdhulipudi,

 

Thanks for the response!

 

Below is the Cache rule and invalidation rule configured in the dispatcher.

 

/filter
{
    /0022 { /type "allow" /url "/bin/myproject/*" }
}
 
/cache
{
    /rules
    {
        /0000
        {
            /glob "*"
            /type "allow"
        }
    }
 
    /invalidate
    {
        /0000
        {
            /glob "*"
            /type "deny"
        }
        /0001
        {
            /glob "*.html"
            /type "allow"
        }
        /0002
        {
            /glob "/bin/myproject/servlet"
            /type "allow"
        }
    }
}
 
 
Also tried below invalidation rule, which also doesn't resolve the issue
/invalidate
    {
        /0000
        {
            /glob "*"
            /type "allow"
        }
   }
SureshDhulipudi
Community Advisor
Community Advisor
March 4, 2024

can you try with

        /0002
        {
            /glob "/bin/myproject/servlet/*"
            /type "allow"
        }

 

Raja_Reddy
Community Advisor
Raja_ReddyCommunity AdvisorAccepted solution
Community Advisor
March 3, 2024

Hi @sriabinaya_subramani 

Based on the logs you provided, it seems that the resource-only-flush request was successful and the invalidation request was received by the dispatcher. However, it's possible that the cached JSON files for all countries were not cleared because the invalidation request was not specific enough.

When you trigger a resource-only-flush request for `/bin/myproject/servlet`, it invalidates the cache for that specific path only. It does not invalidate the cache for any child paths or any other paths that may be related to the servlet.

To clear the cached JSON files for all countries, you may need to trigger a resource-only-flush request for each country-specific path, such as `/bin/myproject/servlet/us/en/myservlet.json`, `/bin/myproject/servlet/uk/en/myservlet.json`, etc. This will ensure that the cache for each country-specific path is cleared and the updated JSON files are served from the publish instance.

Alternatively, you can trigger a full cache flush on the dispatcher to clear all cached content. However, this may not be desirable if you have a large amount of cached content or if you want to minimize the impact on the dispatcher performance.

Thanks,
Raja

Level 2
March 4, 2024

Thank you @raja_reddy for the reply.

The root cause you have mentioned seems to be convincing, and we will attempt to initiate the flush request for the servlet specific to the country.