Disable SerlvetPathMatches caching of welcome files

41 views
Skip to first unread message

Brad Wood

unread,
Dec 20, 2021, 3:46:25 PM12/20/21
to Undertow Dev
Is it possible to disable the caching of welcome files in the ServletPathMatcher class?  I'm playing with some dynamic behaviors where I have a custom resource manager which serves content from different folders based on data in the servlet.  

To clarify, there is
  • A single server deployment
  • A single servlet deployment
  • A single (bespoke) resource manager
  • More than one folder to serve content from which is dynamically determined in my custom resource manager
Overall, everything is working well (And I'm doing this sort of oddball thing to mimic how Adobe ColdFuson's version of Tomcat allows more than one host/web root in a single deployment, controlled by the front end server's virtual hosts).  The problem is, whichever site I hit first caches the lookups for the welcome files and never performs the lookup again.  So if one content root has an index.cfm and the other doesn't, undertow tries to load it anyway, or vice versa.

I can see the allure of caching these lookups, but it simply doesn't work here.  I would prefer to implement my own cached resource manager (which takes into account the dynamic content roots) and have the servlet path match classes not try to cache anything on its own. Even if this was a non-standard setting I could enable/disable.

Is this possible?  My initial review of the Undertow source doesn't reveal a way to disable these caches.  And the SerlvetPathMatches.invalidate() method, in addition to being seemingly heavy-handed, is not thread safe from my testing.  I also see logic for a ResourceChangeListener, but this also wouldn't help here since the actual file system isn't being modified.

Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 

Brad Wood

unread,
Dec 20, 2021, 4:11:56 PM12/20/21
to Undertow Dev
After thinking on this a bit more, an easy solution may be to have the servlet path matches class base its welcome file caching on the result of 

resourcemanger.getResource( "/" )

That way the file lookups could be cached, but still potentially different depending what content root the resource manager was looking at for that request.

Flavia Rainone

unread,
Feb 3, 2022, 5:03:03 PM2/3/22
to Undertow Dev
Brad,

I don't think that there is a way of doing this currently, but we could add this new feature, that would be disabled by default. Please go ahead and create a Jira with your suggestions for this and we'll follow up from there.

Brad Wood

unread,
Feb 4, 2022, 4:07:58 PM2/4/22
to Undertow Dev
I have created a ticket here


I think this is a pretty simple change, and honestly it may be possible to change the cache to use the absolute path instead of the relative path in a manner that is backwards compatible and just as performant.  If so, it wouldn't require a feature flag around it.  

Reply all
Reply to author
Forward
0 new messages