Continue to spit groove in net there is no suitable disk cache to use Ehcache

Source: Internet
Author: User
Tags net domain

  

Talking about caching, everyone may be eloquent, all kinds of cache can be analyzed, but in net to find a suitable disk cache seems to be a bit difficult.

One: Background

The thing is this, in a recent project, you need to draw some reports on the web, because the base data source of the report is full-memory, so the memory is relatively tight for us, we may

You know, for example, some scatter graphs, this type of report data is very much, in order to speed up, I need to cache two kinds of data:

1. Based on the underlying data source to calculate the intermediate results, for the next acceleration, cache for a few 10 minutes, this data volume is relatively large.

2. The response of the service is cached for 30 minutes, and the amount of data is relatively large, probably 10-50m.

Just said, the memory is more tight, if you put these data into memory is more embarrassing, but also business is not allowed, if you put such a large chunk of data in the distributed cache, the traffic up after the

Wide is also a problem, will be more risk of time-out, so the best way is to use the native disk cache , so you can take a balance in performance and memory ~ ~ ~

Two: Find solutions

  

Balance point found, seemingly in the. NET domain is rarely heard of the concept of disk caching, since there is little to hear, it is in the wave of NuGet, and then found a top1 diskcache, such as:

Pull down a test, lying trough, on a curd operation, even TTL and TTI functions are not, also want to donate Bitcoin , O (∩_∩) o

Since NET does not have any good solution, the eye can only cast to Java below to see, soon found the Ehcache, look at the official explanation is Bull Fork of, intervene the way or with previous article, use thrift do C #

and the interaction medium between Java is possible. (The specific use of thrift, probably can see an article) such as:

Three: Configuration of Ehcache

1. MAVEN's Ehcache Address

         <!--https://mvnrepository.com/artifact/org.ehcache/ehcache-         <dependency>             <groupId>org.ehcache</groupId>             <artifactId>ehcache</artifactId>             < Version>3.5. 2</version>        </dependency>

Ehcache Official website: http://www.ehcache.org/, we can simply understand, the specific use of the official are some samples, in the Dbengines ranking is also very good.

2. Using the full code mode configuration

 

Next, you can write a code test, insert a 10,000-character cache into diskcache, insert 1000 times, and see how efficient the code looks like:

 Public classApp { Public Static voidMain (string[] args)throwscachepersistenceexception {localpersistenceservice persistenceservice=NewDefaultlocalpersistenceservice (NewDefaultpersistenceconfiguration (NewFile ("C:\\1\\cache"))); Persistentusermanagedcache<string, string> cache =usermanagedcachebuilder. Newusermanagedcachebuilder (String.class, String.class). With (NewUsermanagedpersistencecontext<string, string> ("Persistentcache", Persistenceservice)) . Withresourcepools (Resourcepoolsbuilder.newresourcepoolsbuilder (). Disk (10L, MEMORYUNIT.GB,true). Withexpiry (Expirations.timetoliveexpiration (Duration.of (timeunit.minutes)). Build (true); StringBuilder Sbuilder=NewStringBuilder ();  for(inti = 1; I < 10000; i++) {sbuilder.append (i); }        LongStartTime = System.currenttimemillis ();//Get start time         for(inti = 1; i < 1000; i++) {String key= "username" +i; String value=sbuilder.tostring ();            Cache.put (key, value); System.out.println (String.Format ("%s: current key=%s inserted into cache", I, key)); }        LongEndTime = System.currenttimemillis ();//Get end TimeSystem.out.println ("Program Run Time:" + (Endtime-starttime) + "MS"); }}

The speed is probably more than 600 milliseconds, the time is acceptable, in my project is also more suitable.

Of course, you can also use XML to dynamically configure the Ehcache, or the use of spring data to integrate this ehcache is possible, because the main use of Java to play auxiliary, not specifically in-depth introduction,

OK, so much for this article, I hope it will help you.

Continue to spit groove in net there is no suitable disk cache to use Ehcache

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.