Caching overview
The cache module uses EhCache as the default JVM in-process cache service, implements a lightweight cache framework for multi-level caching (MultiLevel) by integrating external Redis services, and is deeply integrated with the YMP framework (supporting class methods) Caching, which can be cached based on method parameter values), flexible configuration, easy to use and expand;
Maven package dependency
<dependency> <groupId>net.ymate.platform</groupId> <artifactId>ymate-platform-cache</artifactId> <version>2.0-SNAPSHOT</version> </dependency>
Note:
- Add the above configuration in the project's pom.xml. This module has introduced core package dependencies by default, and there is no need to repeat the configuration.
If you need to enable redis as a cache service, please add the following dependency configuration:
<dependency> <groupId>net.ymate.platform</groupId> <artifactId>ymate-platform-persistence-redis</artifactId> <version>2.0-SNAPSHOT</version> </dependency>
Basic interface concept
Developers can complete the custom extension implementation of the cache module according to the following interface;
Cache service provider (ICacheProvider )Interface:
- DefaultCacheProvider - The default cache service provider interface implementation class based on the EhCache cache service;
- RedisCacheProvider - The cache service provider interface implementation class based on the Redis database;
- MultievelCacheProvider - A cache service provider interface implementation class that integrates EhCache and Redis, and determines how to obtain cache objects through MultilevelKey;
Cache Key generator ( IKeyGenerator) interface:
- DefaultKeyGenerator - generates a cache Key based on the provided class method and parameter object. The default is to serialize the method and parameter object and then take its MD5 value;
Serialization service (ISerializer) interface:
- DefaultSerializer - The default serialization service is implemented using the object serialization technology that comes with JDK;
Cache event listening (ICacheEventListener) interface: used to monitor event processing when cached objects change, developers need to implement the interface;
Cache scope processing ICacheScopeProcessor interface: The Scope parameter used to process the @Cacheable annotation is set to a non-DEFAULT scope cache object, and developers need to implement the interface;