Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Apache CXF SOAP Client Caching  RSS feed

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a WebService for which I generate my client using the Apache CXF framework. I then call my services using the code below:



I have a couple of questions around it:

Can I cache the factory that I create as the first step in the code above?

Should I cache the myServiceClient that I create above and re-use if for subsequent WebService calls? or should I create one client per request?

The reason is that I will be calling these WebServices every 15 seconds or so and I'm not sure which one to have in cache so that I don't end up creating too many instances!
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any suggestions?
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is an inherent characteristic of the Factory design pattern that you should be able to construct a Factory once and re-use it thereafter. Otherwise, why bother with a Factory instead of just using a constructor?

Instances created by a factory are a different matter. The other characteristic of a Factory is to be able to produce a product rapidly, which it may do by employing an internal cache or pool. So the overhead for factory products is typically very low. And the properties of the product in question may either have a limited lifetime (for example, network connections that time out), need cleanup (files and connections to close), or may become so dirty in the course of use that it's less trouble to simple obtain a new one.

So as a general rule, I'd cache the factory and use it to create clients on-demand.

It doesn't hurt to read the instructions, though, just in case there are special considerations.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!