Results 1 to 4 of 4

Thread: Advanced Cache Objects in Java

  1. #1
    Join Date
    Feb 2009
    Posts
    105

    Advanced Cache Objects in Java

    Before complicate life designing a caching system, it is very possible that we should look online at the usual places, to see what there is on the subject. In the Java world, we must not forget how it defines the new specifications. This is through the JCP (Java community process).


    Looking up, we find that there is a recommended product functionality for caching, called OSCACHE. After downloading the ZIP file with the libraries and documentation, so that our proof of concept work, we can establish a file structure.

  2. #2
    Join Date
    Feb 2009
    Posts
    105

    Re: Advanced Cache Objects in Java

    We must modify the web.xml file to reference library TAGS:
    Code:
    <taglib>
          <taglib-uri> oscache </ taglib-uri>
          <taglib-location> / WEB-INF/oscache.tld </ taglib-location>
     </ Taglib>
    We also have to play the oscache.properties configuration file and display the contents persistent cache directory.

    Code:
     # CACHE DIRECTORY # # 
    This is the directory on disk caches WHERE will be stored by the DiskPersistenceListener. 
    # It will be created if it does Already exist.  Remember That OSCache must-have 
    # write permission to this directory. 
    # # Note: for Windows machines, this Needs \ to be escaped # ie Windows:
    # cache.path = c: \ \ myapp \ \ cache # or * ix: # cache.path = / opt / myapp / cache 
    # cache.path = d: \ \ cacheadictos \ \ WEB-INF \ \ cache
    Our JSP, refers to a tag library in order to have the game of TAGS to help us in our work:
    <% @ Taglib uri = "oscache" prefix = "cache"%>
    Declaring an area that we want to cache is as simple as including a block like this:
    <Cache: cache key = "Zona1" scope = "application" duration = "10">
    Depending on the type of application and scope of the cache element can play with different modifiers: key, scope and duration (see the documentation for more details and other related labels). We have specified that we want all users have this cached content and every 10 seconds to cool.

  3. #3
    Join Date
    Feb 2009
    Posts
    105

    Re: Advanced Cache Objects in Java

    To prove that it behaves as we want, we'll put a delay in one area and run the query several times .... the result will surprise you. As usual in this web, look on substance rather than form .....
    HTML Code:
     <% @ Taglib uri = "oscache" prefix = "cache"%>
     <% @ Page contentType = "text / html"%>
     <html>
     <title> <head> JSP Page </ title> </ head>
     <body>
    
     <%!  int counter = 0;%>
    
     <center>
     Examples of Caches <h1> with OSCache </ h1>
    
     <% Long start = System.currentTimeMillis (); 
    
      counter + +; 
      %>
     <br>
    
     <Cache: cache key = "Zona1" scope = "application" duration = "10">
    
      <% 
    
      try 
      ( 
          Thread.currentThread (). Sleep (3000); 
    
          java.util.Date date = new java.util.Date (); 
    
          out.println ("This is the message" + date); 
      ) 
      catch (Exception e) () 
    
      %> 
    
     </ Cache: cache> 
    
     <br>
    
     <%  
    
      long end = System.currentTimeMillis () - start; 
      out.println ("The full time is:" + order 
     + "Milliseconds and the counter is:" + counter);%> </ center> </ body> </ html>
    In a normal application, the time should always be greater than three seconds .... but we see that indeed the time of the second request goes to zero ...

    This example can be very useful when working with the MVC design pattern type 1 (using JavaBeans and JSP tags to access data structures). If we continue researching the product, we will soon see that there is an object model equivalent for other applications using MVC design as type 2 or traditional applications.

  4. #4
    Join Date
    Jul 2010
    Posts
    2

    Re: Advanced Cache Objects in Java

    I think its very useful for all the software people..

Similar Threads

  1. Return value of generic objects in java
    By Amy Adams in forum Software Development
    Replies: 4
    Last Post: 30-03-2010, 11:42 AM
  2. Array of objects in java
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 27-02-2010, 02:05 AM
  3. What are an Immutable Objects in Java?
    By Silent~Kid in forum Software Development
    Replies: 4
    Last Post: 19-02-2010, 06:35 AM
  4. Access to Objects In A JavaBean From Another Java Bean
    By ramsun in forum Software Development
    Replies: 5
    Last Post: 30-01-2010, 01:18 PM
  5. Comparison between core java and advanced java
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 19-01-2010, 10:57 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,582,147.11814 seconds with 17 queries