简体   繁体   English

缓存实施的最佳做法

[英]Best practices on cache implementation

I would need to implement cache, which would need to perform SQL queries and cache results. 我需要实现缓存,这需要执行SQL查询和缓存结果。 So, I would love to read something about best practices of doing that; 因此,我很想阅读一些有关最佳做法的内容; how do properly, staling cache results, checking, etc. Particularly, I would probably benefit from learning how Hibernate is doing that? 特别是,我可能将从学习Hibernate的操作中受益吗? Or some other good players :-) 或其他一些好手:-)

One approach in the Java world is to use the OpenSymphony Cache . Java世界中的一种方法是使用OpenSymphony Cache This is a distributed cache (like memcached) that lets you store any Java objects and set expiration policies. 这是一个分布式缓存(如memcached),使您可以存储任何Java对象并设置过期策略。

If you use iBatis as your Java persistence manager, you can leverage its integration with OSCache. 如果将iBatis用作Java持久性管理器,则可以利用其与OSCache的集成。 The Hibernate ORM also has an OSCache integration . Hibernate ORM还具有OSCache集成

The best practice is to not cache database queries, but things you do with database queries. 最佳做法是不缓存数据库查询,而是缓存数据库查询。 That is, you do a database query because you want an object that is represented by the data the query gives you. 也就是说,您执行数据库查询是因为您想要一个由查询提供的数据表示的对象。 That's what you should cache. 那就是您应该缓存的内容。

Hibernate does some of this, and you can of course mix hibernate and memcached to get the benefits of memcached. Hibernate可以做到这一点,您当然可以将hibernate和memcached混合使用以获得memcached的好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM