Archive for February, 2008

Caching in practice a region named db1.auction.model.Category. This

Tuesday, February 26th, 2008

Caching in practice a region named db1.auction.model.Category. This setting is necessary if your application works with multiple SessionFactory instances or persistence units. Without it, cache region names of different persistence units may conflict. Now that you know about cache regions, you can configure the physical properties of the auction.model.Category cache. First let s choose a cache provider. Suppose you re running your auction application in a single JVM, so you don t need a cluster-aware provider. 13.4.3 Setting up a local cache provider You need to set the configuration property that selects a cache provider: hibernate.cache.provider_class = org.hibernate.cache.EhCacheProvider You choose EHCache as your second-level cache in this case. Now, you need to specify the properties of the cache regions. EHCache has its own configuration file, ehcache.xml, in the classpath of the application. The Hibernate distribution comes bundled with example configuration files for all bundled cache providers, so we recommend that you read the usage comments in those files for detailed configuration and assume the defaults for all options we don t mention explicitly. A cache configuration in ehcache.xml for the Category class may look like this: There are a small number of Category instances. You therefore disable eviction by choosing a cache size limit greater than the number of categories in the system and setting eternal=”true”, disabling eviction by timeout. There is no need to expire cached data by timeout because the Category cache concurrency strategy is read-write and because there are no other applications changing category data directly in the database. You also disable disk-based cache overflow, because you know there are few instances of Category and so memory consumption won t be a problem. Bids, on the other hand, are small and immutable, but there are many of them, so you must configure EHCache to carefully manage the cache memory consumption. You use both an expiry timeout and a maximum cache size limit:
We recommend high quality webhost to host and run your jsp application: christian web host services.

Free web hosts - CHAPTER 13 Optimizing fetching and caching

Sunday, February 24th, 2008

CHAPTER 13 Optimizing fetching and caching You apply a read-only strategy for the Bid class: Bid data is therefore never expired from the cache, because it can only be created and never updated. (Bids may of course be expired by the cache provider for example, if the maximum number of objects in the cache is reached.) Hibernate also removes the data from the cache if a Bid instance is deleted, but it doesn t provide any transactional guarantees in doing so. User is an example of a class that could be cached with the nonstrict-read-write strategy, but we aren t certain that it makes sense to cache users. Let s set the cache provider, its expiration policies, and the physical regions of your cache. You use cache regions to configure class and collection caching individually. 13.4.2 Understanding cache regions Hibernate keeps different classes/collections in different cache regions. A region is a named cache: a handle by which you may reference classes and collections in the cache provider configuration and set the expiration policies applicable to that region. A more graphical description is that regions are buckets of data, of which there are two types: One type of region contains the disassembled data of entity instances, and the other type contains only identifiers of entities that are linked through a collection. The name of the region is the class name in the case of a class cache, or the class name together with the property name in the case of a collection cache. Category instances are cached in a region named auction.model.Category, whereas the items collection is cached in a region named auction.model.Category.items. The Hibernate configuration property named hibernate.cache.region_pre fix may be used to specify a region name prefix for a particular SessionFactory or persistence unit. For example, if the prefix is set to db1, Category is cached in
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Caching in practice would rely only on cache (Tomcat web server)

Saturday, February 23rd, 2008

Caching in practice would rely only on cache expiration (timeout), but you prefer changes to categories to be visible immediately. The class caches are always enabled for a whole hierarchy of persistent classes. You can’t only cache instances of a particular subclass. This mapping is enough to tell Hibernate to cache all simple Category property values, but not the state of associated entities or collections. Collections require their own region. For the items collection you use a read-write concurrency strategy: The region name of the collection cache is the fully qualified class name plus the collection property name, auction.model.Category.items. The @org.hibernate.annotations.Cacheannotation can also be declared on a collection field or getter method. This cache setting is effective when you call aCategory.getItems() in other words, a collection cache is a region that contains which items are in which category. It s a cache of identifiers only; there is no actual Category or Item data in that region. If you require the Item instances themselves to be cached, you must enable caching of the Item class. A read-write strategy is especially appropriate. Your users don t want to make decisions (placing a bid, for example) based on possibly stale Item data. Let s go a step further and consider the collection of bids: A particular Bid in the bids collection is immutable, but the collection of bids is mutable, and concurrent units of work need to see any addition or removal of a collection element without delay:
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

CHAPTER 13 Optimizing (Linux web host) fetching and caching strategy you d

Saturday, February 23rd, 2008

CHAPTER 13 Optimizing fetching and caching strategy you d like to use for each class and each collection. In the second step, you enable your preferred cache provider in the global Hibernate configuration and customize the provider-specific settings and physical cache regions. For example, if you re using OSCache, you edit oscache.properties, or for EHCache, ehcache.xml in your classpath. Let s enable caching for the CaveatEmptor Category, Item, and Bid classes. 13.4 Caching in practice First we ll consider each entity class and collection and find out what cache concurrency strategy may be appropriate. After we select a cache provider for local and clustered caching, we ll write their configuration file(s). 13.4.1 Selecting a concurrency control strategy The Category has a small number of instances and is updated rarely, and instances are shared between many users. It s a great candidate for use of the second- level cache. Start by adding the mapping element required to tell Hibernate to cache Category instances. The usage=”read-write” attribute tells Hibernate to use a read-write concurrency strategy for the auction.model.Category cache. Hibernate now hits the second-level cache whenever you navigate to a Category or when you load a Category by identifier. If you use annotations, you need a Hibernate extension: @Entity @Table(name = “CATEGORY”) @org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE ) public class Category { … } You use read-write instead of nonstrict-read-write because Category is a highly concurrent class, shared between many concurrent transactions. (It s clear that a read committed isolation level is good enough.) A nonstrict-read-write
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Caching fundamentals Choosing a cache provider For now, (Adelphia web hosting)

Friday, February 22nd, 2008

Caching fundamentals Choosing a cache provider For now, Hibernate forces you to choose a single cache provider for the whole application. Providers for the following open source products are built into Hibernate: EHCache is a cache provider intended for a simple process scope cache in a single JVM. It can cache in memory or on disk, and it supports the optional Hibernate query result cache. (The latest version of EHCache now supports clustered caching, but we haven t tested this yet.) OpenSymphony OSCache is a service that supports caching to memory and disk in a single JVM, with a rich set of expiration policies and query cache support. SwarmCache is a cluster cache based on JGroups. It uses clustered invalidation but doesn t support the Hibernate query cache. JBoss Cache is a fully transactional replicated clustered cache also based on the JGroups multicast library. It supports replication or invalidation, synchronous or asynchronous communication, and optimistic and pessimistic locking. The Hibernate query cache is supported, assuming that clocks are synchronized in the cluster. It s easy to write an adaptor for other products by implementing org.hibernate. cache.CacheProvider. Many commercial caching systems are pluggable into Hibernate with this interface. Not every cache provider is compatible with every concurrency strategy! The compatibility matrix in table 13.1 will help you choose an appropriate combination. Setting up caching involves two steps: First, you look at the mapping metadata for your persistent classes and collections and decide which cache concurrency Table 13.1 Cache concurrency strategy support Concurrency strategy cache provider Read-only Nonstrictread- write Read-write Transactional EHCache X X X OSCache X X X SwarmCache X X JBoss Cache X X
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Make web site - CHAPTER 13 Optimizing fetching and caching have to

Thursday, February 21st, 2008

CHAPTER 13 Optimizing fetching and caching have to decide, for each persistent class and collection, which cache concurrency strategy to use if you want to enable the second-level cache. The four built-in concurrency strategies represent decreasing levels of strictness in terms of transaction isolation: Transactional Available in a managed environment only, it guarantees full transactional isolation up to repeatable read, if required. Use this strategy for read-mostly data where it s critical to prevent stale data in concurrent transactions, in the rare case of an update. Read-write This strategy maintains read committed isolation, using a time- stamping mechanism and is available only in nonclustered environments. Again, use this strategy for read-mostly data where it s critical to prevent stale data in concurrent transactions, in the rare case of an update. Nonstrict-read-write Makes no guarantee of consistency between the cache and the database. If there is a possibility of concurrent access to the same entity, you should configure a sufficiently short expiry timeout. Otherwise, you may read stale data from the cache. Use this strategy if data hardly ever changes (many hours, days, or even a week) and a small likelihood of stale data isn t of critical concern. Read-only A concurrency strategy suitable for data which never changes. Use it for reference data only. Note that with decreasing strictness comes increasing performance. You have to carefully evaluate the performance of a clustered cache with full transaction isolation before using it in production. In many cases, you may be better off disabling the second-level cache for a particular class if stale data isn t an option! First benchmark your application with the second-level cache disabled. Enable it for good candidate classes, one at a time, while continuously testing the scalability of your system and evaluating concurrency strategies. It s possible to define your own concurrency strategy by implementing org. hibernate.cache.CacheConcurrencyStrategy, but this is a relatively difficult task and appropriate only for rare cases of optimization. Your next step after considering the concurrency strategies you ll use for your cache candidate classes is to pick a cache provider. The provider is a plug-in, the physical implementation of a cache system.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Caching fundamentals (Web hosting resellers) ated with EntityManagers of a particular

Wednesday, February 20th, 2008

Caching fundamentals ated with EntityManagers of a particular persistence unit) share the same second- level cache. Persistent instances are stored in the second-level cache in a disassembled form. Think of disassembly as a process a bit like serialization (the algorithm is much, much faster than Java serialization, however). The internal implementation of this process/cluster scope cache isn t of much interest. More important is the correct usage of the cache policies caching strategies and physical cache providers. Different kinds of data require different cache policies: The ratio of reads to writes varies, the size of the database tables varies, and some tables are shared with other external applications. The second-level cache is configurable at the granularity of an individual class or collection role. This lets you, for example, enable the second-level cache for reference data classes and disable it for classes that represent financial records. The cache policy involves setting the following: Whether the second-level cache is enabled The Hibernate concurrency strategy The cache expiration policies (such as timeout, LRU, and memory-sensitive) The physical format of the cache (memory, indexed files, cluster-replicated) Not all classes benefit from caching, so it s important to be able to disable the second- level cache. To repeat, the cache is usually useful only for read-mostly classes. If you have data that is updated much more often than it s read, don t enable the second-level cache, even if all other conditions for caching are true! The price of maintaining the cache during updates can possibly outweigh the performance benefit of faster reads. Furthermore, the second-level cache can be dangerous in systems that share the database with other writing applications. As explained in earlier sections, you must exercise careful judgment here for each class and collection you want to enable caching for. The Hibernate second-level cache is set up in two steps. First, you have to decide which concurrency strategy to use. After that, you configure cache expiration and physical cache attributes using the cache provider. Built-in concurrency strategies A concurrency strategy is a mediator: It s responsible for storing items of data in the cache and retrieving them from the cache. This is an important role, because it also defines the transaction isolation semantics for that particular item. You ll
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

CHAPTER 13 Optimizing fetching and caching persistent instances.

Tuesday, February 19th, 2008

CHAPTER 13 Optimizing fetching and caching persistent instances. A cache concurrency strategy defines the transaction isolation details for a particular item of data, whereas the cache provider represents the physical cache implementation. Use of the second-level cache is optional and can be configured on a per-class and per-collection basis each such cache utilizes its own physical cache region. Hibernate also implements a cache for query resultsets that integrates closely with the second-level cache. This is an optional feature; it requires two additional physical cache regions that hold the cached query results and the timestamps when a table was last updated. We discuss the query cache in the next chapters because its usage is closely tied to the query being executed. We ve already discussed the first-level cache, the persistence context, in detail. Let s go straight to the optional second-level cache The Hibernate second-level cache The Hibernate second-level cache has process or cluster scope: All persistence contexts that have been started from a particular SessionFactory (or are associ- Figure 13.7 Hibernate s two-level cache architecture
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Caching fundamentals Data that changes rarely (Web hosting ratings)

Monday, February 18th, 2008

Caching fundamentals Data that changes rarely Noncritical data (for example, content-management data) Data that is local to the application and not shared Bad candidates for second-level caching are Data that is updated often Financial data Data that is shared with a legacy application These aren t the only rules we usually apply. Many applications have a number of classes with the following properties: A small number of instances Each instance referenced by many instances of another class or classes Instances that are rarely (or never) updated This kind of data is sometimes called reference data. Examples of reference data are ZIP codes, reference addresses, office locations, static text messages, and so on. Reference data is an excellent candidate for caching with a process or cluster scope, and any application that uses reference data heavily will benefit greatly if that data is cached. You allow the data to be refreshed when the cache timeout period expires. We shaped a picture of a dual layer caching system in the previous sections, with a unit of work-scoped first-level and an optional second-level process or clus ter scope cache. This is close to the Hibernate caching system. 13.3.2 The Hibernate cache architecture As we hinted earlier, Hibernate has a two-level cache architecture. The various elements of this system can be seen in figure 13.7: The first-level cache is the persistence context cache. A Hibernate Session lifespan corresponds to either a single request (usually implemented with one database transaction) or a conversation. This is a mandatory first-level cache that also guarantees the scope of object and database identity (the exception being the StatelessSession, which doesn t have a persistence context). The second-level cache in Hibernate is pluggable and may be scoped to the process or cluster. This is a cache of state (returned by value), not of actual
We recommend high quality webhost to host and run your jsp application: christian web host services.

CHAPTER 13 Optimizing fetching and caching Let s discuss (Bulletproof web design)

Sunday, February 17th, 2008

CHAPTER 13 Optimizing fetching and caching Let s discuss which data benefits from second-level caching in other words, when to turn on the process (or cluster) scope second-level cache in addition to the mandatory first-level transaction scope cache. Caching and transaction isolation A process or cluster scope cache makes data retrieved from the database in one unit of work visible to another unit of work. This may have some nasty side effects on transaction isolation. First, if an application has nonexclusive access to the database, process scope caching shouldn t be used, except for data which changes rarely and may be safely refreshed by a cache expiry. This type of data occurs frequently in content management- type applications but rarely in EIS or financial applications. There are two main scenarios for nonexclusive access to look out for: Clustered applications Shared legacy data Any application that is designed to scale must support clustered operation. A process scope cache doesn t maintain consistency between the different caches on different machines in the cluster. In this case, a cluster scope (distributed) second- level cache should be used instead of the process scope cache. Many Java applications share access to their database with other applications. In this case, you shouldn t use any kind of cache beyond a unit of work scoped first-level cache. There is no way for a cache system to know when the legacy application updated the shared data. Actually, it s possible to implement application- level functionality to trigger an invalidation of the process (or cluster) scope cache when changes are made to the database, but we don t know of any standard or best way to achieve this. Certainly, it will never be a built-in feature of Hibernate. If you implement such a solution, you ll most likely be on your own, because it s specific to the environment and products used. After considering nonexclusive data access, you should establish what isolation level is required for the application data. Not every cache implementation respects all transaction isolation levels and it s critical to find out what is required. Let s look at data that benefits most from a process- (or cluster-) scoped cache. In practice, we find it useful to rely on a data model diagram (or class diagram) when we make this evaluation. Take notes on the diagram that express whether a particular entity (or class) is a good or bad candidate for second-level caching. A full ORM solution lets you configure second-level caching separately for each class. Good candidate classes for caching are classes that represent
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.