Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6643231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:01:38+00:00 2026-05-26T00:01:38+00:00

I am using 2 modules in my java application which downloads the same web

  • 0

I am using 2 modules in my java application which downloads the same web page.
So in effect the site is downloaded twice.
In order to avoid this , is there some caching layer i can attach , so that only 1 copy of the site is actually downloaded.

I would love to see the caching at Java side , if not possible at a later level like some web caching proxy or something

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:01:38+00:00Added an answer on May 26, 2026 at 12:01 am

    If the two ‘modules’ are in the same jvm and thus can access eachothers memory, try a singleton based ‘cache’. I tend to use a HtmlSnippit cache for caching much repeated HTML snippits with great success:

    public class Testing {
        public static void main(String[] args) {
    
        String html = "<div>The quick brown fox jumps over the lazy dog</div>";
    
        /* Access via the getInstance() getter */
        HtmlSnippitCache.getInstance().putSnippit("FOXY", html);
    
        /* Or via local var */
        HtmlSnippitCache cache = HtmlSnippitCache.getInstance();
        String moreHtml = cache.getSnippit("FOXY");
    
        System.out.println(moreHtml);
    }
    
    public static class HtmlSnippitCache {
        /* Singleton implementation */
        private static HtmlSnippitCache instance;
    
        public static HtmlSnippitCache getInstance() {
            if (HtmlSnippitCache.instance == null)
                synchronized (HtmlSnippitCache.class) {
                    if (HtmlSnippitCache.instance == null)
                        HtmlSnippitCache.instance = new HtmlSnippitCache();
                }
            return HtmlSnippitCache.instance;
        }
    
        /* Ensure only local construction. */
        private HtmlSnippitCache() {}
    
        /* Clas Impl */
        private HashMap<String, String> map = new HashMap<String, String>();
    
        public boolean containsSnippit(String key) {
            return map.containsKey(key);
        }
    
        public String getSnippit(String key) {
            return map.get(key);
        }
    
        public String putSnippit(String key, String value) {
            return map.put(key, value);
        }
    
            public int size() {
                return map.size();
            }
        }
    }
    

    Now, the getSnippit() and putSnippit() methods will probably need to be synchronized somehow for thread safety, but that’s another discussion (argument?) altogether 🙂

    (Example should run out of the box.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large application (~50 modules) using a structure similar to the following:
I've written an application using wxPython and various other small modules (xlrd, xlwrt, pyserial,
I have troubles using the java ServiceLoader in a NetBeans module application. Here is
I've a SmartGWT application which interacts with a mysql database using rpc services. Suppose
I have a JavaEE6 application, consisting of Web stuff and EJBs and which is
I want to assemble a web module which looks like the following: src/main/java (has
I have a Java EE application consisting of 1 web module and 1 EJB
I've written a simple Java Console Application in Eclipse that references a WCF web
In my gwt application somebody developed a module which uses java.beans.PropertyChangeSupport. Recently I have
APPLICATION and ENVIRONMENT Java EE / JSF2.0 / JPA enterprise application, which contains a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.