We know that cache is the cache category defined in the EHCACHE.XML configuration file, getting a particular cache category is as follows:
Cache cache = cacheManager.getcache (cachename); cachename is a cache class name you want to get. Then put an object in the above-defined cache:
Cache.put (New Element); Key is the index value of the object in this cache, and the value is the object corresponding to the key in the cache. We see that Value in the cache must be serialized, Java native type
CHAR, INT, native type of packaging class String, Character, Integer, Number ... and collection List implementation class ArrayList has implemented the serializable interface, which can be placed directly in the cache. It should be noted here that the Iterator that is often used in the method return value does not implement the serializable interface, so the Cache cannot cache the method of the return value of the Iterator.
It is also important to note that if we want to make a cache is called (for example, setter, init) in the initial phase of the lifecycle of the bean, the method cache the interceptor has not been called executed yet, then the cache will be Role, such as making the following configuration:
INIT-method = "init" autowire = "byname" /> Property> list> Property> bean> The cache method that is called in the initial method of the init initial method will be invalid.