Several ways to refresh and read the data dictionary cache

Source: Internet
Author: User

Before has written the data dictionary related business is how to do, has the friend message asks how to read, actually very simple, the simplest way is every time reads the database, but this kind of practice is very bad, because the data dictionary belongs to the cold resource in the database, does not often become the data, such data uses the cache to do is best, Access to the database before the request to the database is directly intercepted, so as to reduce the pressure on the database, after all, many pages for the data dictionary access is still too much

Just take a quick look at a picture:

So how do you put the data into Redis? The mainstream of the two ways to say it roughly:

    1. After each operation of the edit data dictionary, a message queue is sent, which is recorded separately in the Redis maintenance (this way I personally do not like it, because sometimes it is wrong to rewrite or delete, so frequent operation more)

    2. After each data dictionary additions and deletions, and finally manually perform the refresh, so that the bulk of the data into the cache, and finally on the page can be directly used

In this small part I use the second way,


On the previous page with a refresh cache button, dynamic Ajax to the background, read the database data dictionary and then flush into the cache (some people say that such frequent operation will be very bad, that is to say, but the operation of this permission only after the successful release of the project, and then perform the operation, is generally midnight, no impact. --)

Let's take a look at the database data

And look at the data in the cache.


It's not hard to see that all one by one correspond

Finally, to look at the custom label, the main purpose is to accept the JSP on the key and the corresponding data dictionary code, and finally return the value

PrivateJedisclient Jedis = Springutils.getcontext (). Getbean (jedisclient.class);  Public voidDotag ()throwsjspexception, IOException {if(Stringutils.isnotempty (TypeCode) &&Stringutils.isnotempty (Ddkey)) {String Ddvalue= Jedis.get (cache_data_dicts + ":" + TypeCode + ":" +Ddkey); JspWriter out=Getjspcontext (). Getout ();        Out.println (Ddvalue); } Else{getjspbody (). Invoke (SW);        Getjspcontext (). Getout (). println (Sw.tostring ()); }    }

<Divclass= "caption">Gender:<Datadict:datadictvalueDdkey= "1"TypeCode= "Sex"/>                         <BR/>type of vehicle:<Datadict:datadictvalueDdkey= "1"TypeCode= "Car_type"/>                                              </Div>

Page effect:

Off-topic, this approach is limited to JSP pages, if your data is from JS render out words (such as jqgrid ah, etc.), then you can write a JS class object, each time incoming code and key call Ajax read from the cache.


?

Several ways to refresh and read the data dictionary cache

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.