Announcement Announcement Module
Collapse
No announcement yet.
Cache loader not called for Spring Gemfire SQL query Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cache loader not called for Spring Gemfire SQL query

    We are using Gemfire cache to store application data and if the data is not found in the cache, we try to get it from the MySQL database using hibernate.

    The database call (When the cache does not have the data) is made from the class implementing CacheLoader interface's load method. The method seems to get called if we search the cache using an id. But how do we make sure the method gets called when we run a sql query against the cache? Or can we write an overloaded method or use a different interface maybe?

    For example, this works fine:

    Code:
    productCache.get(id);
    But what do we do if its an sql query like:
    Code:
    productCache.find("SELECT * FROM /ProductRegion pi WHERE pi.id != null "
                        + "AND pi.getStatus().name() = $1", productStatus.name());
    Below is the class implementing the CacheLoader interface
    Code:
    Public class ProductDBLoader implements CacheLoader<String, Product> { 
    
    @Override
    public Product load(final LoaderHelper<String, Product> helper)
            throws CacheLoaderException {
    
        String id = helper.getKey();
    
        Product product= dao.get(id);
    
        return product;
    }
    
    
     @Override
     public void close() {
     }
    
    }

  • #2
    In general, it's impossible to determine if you have a cache miss by executing a query since it executes over the entire region it can only process existing entries. In your example there could be many items that match the status name in the DB table and the ids are not known. So how would the cache loader be invoked?

    Comment


    • #3
      This is a perfect solution off my problem!!!! Thanks to share for this .



      ------------
      seo expert dubai | http://hotelsinlangkawi.org
      Last edited by smile99; Mar 21st, 2014, 12:40 AM.

      Comment

      Working...
      X