Java開源緩存框架介紹(OSCache,JSC)
OSCache是個(gè)一個(gè)廣泛采用的高性能的J2EE緩存框架,OSCache能用于任何Java應(yīng)用程序的普通的緩存解決方案。
有一個(gè)疑惑。就是JAVA緩存框架與memcache有什么區(qū)別呢?我把所有數(shù)據(jù)查詢出來放在memcache里面不行么?比如說oscache與memcache適用場(chǎng)合有什么區(qū)別呢?
認(rèn)證高級(jí)PHP講師
OSCache has not been updated for a long time. It is recommended to read the official documentation of EHCache.
There are obvious differences betweenehcache, a jvm cache, and memcache, a io-level cache. The following differences determine their use in different scenarios. 優(yōu)點(diǎn)
: It will be more efficient without IO overhead and more flexible to use. 缺點(diǎn)
: However, the public jvm memory will also have an impact on the application itself, and it will be more difficult to share it with multiple applications. (ehcache has a solution that does not use jvm memory)
OSCache or EHCache, the main application scenarios are mostly in-application caching. That is the cache used in my program. All caches are in this program written by myself.
Memcache is an independent process and an independent cache. The cached data is saved in the memory of another process. In my opinion, there are two differences:
Personally, I feel that memcache is similar to a container for objects. It only provides simple functions of putting objects in and removing objects. It can be imagined as a Map.
OSCache is encapsulated on the basis of this kind of object container, providing more powerful functions. It can realize automatic caching of some content through simple configuration files. However, using memcache directly requires writing a lot of additional caching logic and strategy code. .
Using caching, for example, caching some fixed master data, it is very easy to improve website performance by 5-10 times. We use EHCache to easily improve the performance of a course selection system by 7-8 times.
When using cache, the most troublesome thing is dealing with data synchronization. For example, with a redis cache server and a mysql server, you can write data to two databases at the same time, but there will be problems with transaction processing. Cache synchronization is still quite troublesome
OSCache or EHCache is a JVM cache. It cannot be shared by multiple applications or your cluster. This will cause a waste of memory and is suitable for small applications that do not require a cluster. Memcache is an independent cache that can be shared by a cluster or multiple applications. It is suitable for larger applications.
OSCache or EHCache are often used for server local cache. If used directly, it can only be accessed by a single application process. If multiple processes are opened or multiple servers are deployed, each process can only access the local cache. If caching is needed Synchronization requires writing relevant synchronization code. ehcache also supports distributed caching of RMI, JGroups, and JMS, so there is no need to write synchronization code by hand. You can also build a separate EhCache Server, which is almost the same as memcache.
The memcache cache is a separate process. The advantage is that there is less cache synchronization between processes, because there is only one copy of the data on memcache, instead of ehcache having one copy on each process; but access requires inter-process communication, which is more communication overhead.