In a Java project, how to handle caching issues in "interfaces"

Source: Internet
Author: User
Tags delete cache

1, in the service package, respectively, set up a series of interfaces about the cache, classes, etc., encapsulated in a toolkit;

    1. Temporary cached Interfaces (Code section):
 PackageCom.tools;Importjava.util.Date; Public InterfaceCachetemplet {//Set Add persistent cache (cache unique index, cache data)     Public voidAddcache (Object key,object value); //set add cache, but need to have an expiration time limit of milliseconds     Public voidAddcache (Object key,object value,long duration); //setting to add a cache requires a time limit of a date type     Public voidAddcache (Object key,object value,date expire); //Get cache information, get cache information based on key     PublicObject GetCache (object key); //Delete cache information and delete it based on key value     Public voidDelcache (Object key);}

2. Establish a "factory for caching" to get the implementation of the cache, get the cache object from the factory, and then manipulate the cached information from the cache object (get it or delete it);

 PackageCom.tools;//Cache Factory Public classCachefactory {//no parameter constructor    Privatecachefactory () {}//Private member Variables    PrivateCachetemplet Cachetemplet =NULL; //get JVM Cache (not finished)Public Cachetemplet GetCache () {...}
Get Cache
Public Cachetemplet GetCache (Cacheenum cacheenum) {...}
Redis connection Pooling
Private Redispool Redispool;
Next is the corresponding set method, which does not use the Get method,
public void Setredispool (Redispool redispool) {...}
  
private static cachefactory cachefactory = null;
Get Cache Factory
public static Cachefactory Getcachefactory () {...}
.
.
.
.
........
}

3, and then in the corresponding service implementation class, the specific use is as follows: Java code

  

Get the nearest hotel public list<map<string,string>> Putsale (final string product,final string Usertell) {  // First from instantiating the cache temporary object Cachetemplet Cachetemplet = Cachefactory.getcachefactory (). GetCache (Cacheenum.redis);//temporary cache, get cache factory, get cache implementation  //Create Cache entity class object list<map<string,string>> storeinre  = new   Arraylist<map<string, string>> (); map<string, string> e = new hashmap<string, string> (); E.put ("Yxwddh", YXWDDH); Hotel phone Storeinre.add (e);//Add cache information}

  

In a Java project, how to handle caching issues in "interfaces"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.