Combined memcached distributed cache and hibernate (continued)

Source: Internet
Author: User

First, let's take a look at what memcached is.

Memcached is a high-performance, distributed memory object cache system developed by danga interactive. It is used to reduce database load and improve access speed in dynamic applications. Memcached caches are distributed and can be accessed by multiple users on different hosts at the same time. Therefore, the shared memory can only be used for single-host applications, the disk overhead and blocking will not occur when you use a database to do similar things.
Use of memcached
I
Install the memcached server (install it as a system service)
Download file: memcached 1.2.1 for Win32 binaries (Dec 23,200 6)
1. decompress the file to c: \ memcached.
2. Enter 'C: \ memcached \ memcached.exe-D install' in the command line'
3. Enter 'C: \ memcached \ memcached.exe-D start' in the command line to start memcached. The default listening port is 11211.
You can use memcached.exe-h to view its help information.

Problem

If no server is downloaded(If memcached is used) to enable the memcached service, a series of errors will occur. The most important thing is to report connection questions.Question. Therefore, you must install the server when using memcached.

The combination of memcached and Hibernate

Now hibernate implements the seamless connection of memcached. As we have already said, Hibernate's brute force is its cache. It is also quite convenient for hibernate to work with memcached. You only need to configure it, no error occurred while starting the server. The configuration is OK. I read a lot about the combination of Hibernate and memcached on the Internet.ArticleThe content of this article is basically the same. If you are depressed, the reference value will be much less. My company is using memcached as the second-level cache of hibernate. Here we will also sort out relevant content.

The cache mechanism of Hibernate is an important part of its dominant position in the mainstream persistent layer. Its cache mechanism is very pornographic and violent. The level-2 cache is a global cache at the sessionfactory level, which can be specified through hibernate. cache. provider_class of the configuration file. Related configurations are mentioned in the last log. Here I will post it again for you to understand.

Hibernate. cfg. xml

 

Code

  1   <?  XML version = "1.0" encoding = "UTF-8"  ?>  
2   <! Doctype hibernate-configuration public "-// hibernate/hibernate configuration DTD 3.0 // en"
3 Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
4   < Hibernate-Configuration >
5 < Session-factory Name = "Default" >
6 < Property Name = "Hibernate. show_ SQL" > True </ Property >
7 < Property Name = "Hibernate. format_ SQL" > True </ Property >
8 < Property Name = "Hibernate. hbm2ddl. Auto" > Update </ Property >
9 <! -- <Property name = "hibernate. dialect"> org. hibernate. dialect. mysqldialect </property> -->
10 < Property Name = "Hibernate. dialect" > Org. hibernate. dialect. oracle10gdialect </ Property >
11 < Property Name = "Hibernate. JDBC. fetch_size" > 50 </ Property >
12 < Property Name = "Hibernate. JDBC. batch_size" > 0 </ Property >
13 < Property Name = "Hibernate. default_schema" > User </ Property >
14
15 <! -- Hibernate-memcache Configuration -->
16 <! -- Enable Level 2 Cache -->
17 < Property Name = "Hibernate. cache. use_second_level_cache" >
18 True
19 </ Property >
20 <! -- Set cache class -->
21 < Property Name = "Hibernate. cache. provider_class" > Com. googlecode. hibernate. memcached. memcachedcacheprovider </ Property >
22 <! -- Set memcache cache server port -->
23 < Property Name = "Hibernate. memcached. servers" > Localhost: 11211 </ Property >
24 <! -- Set the prefix name of the second-level cache -->
25 < Property Name = "Hibernate. cache. region_prefix" > Quality. cache. ehcache </ Property >
26 <! -- No. cache objects in a structured manner -->
27 < Property Name = "Hibernate. cache. use_structured_entries" > True </ Property >
28 <! -- Cache query results? -->
29 < Property Name = "Hibernate. cache. use_query_cache" > True </ Property >
30
31 < Mapping Resource = "Com/weiruan/projs/mydc/pojos/usert. HBM. xml" />
32 < Mapping Resource = "Com/weiruan/projs/mydc/pojos/developer. HBM. xml" />
33 </ Session-factory >
34   </ Hibernate-Configuration >
35  

Dependent package: hibernate-memcache.jar, memcached-2.3.1.jar, spy2.4, slf4j-1.5.0.jar, slf4j-log4j12-1.5.0.jar and a hibernate-memcached [version]. jar,: http://code.google.com/p/hibernate-memcached/downloads/list.

 

The jar package above is quite a lot on the Internet. I will not be connected here.

Hope

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.