10个将破坏你的系统的不恰当使用缓存

在系统开发中,少不了需要用到缓存来提高程序运行速度,但有时不恰当的使用缓存或许反而使程序变的更慢或者是带来了程序错误,为什么会这样呢,究竟使用缓存应该注意哪些呢?在codeproject中找到一篇文章《Ten-Caching-Mistakes-that-Break-your-App》,这里提到了10处可以改进的地方

  1. Relying on .NET’s default serializer.
  2. Storing large objects in a single cache item.
  3. Using cache to share objects between threads
  4. Assuming items will be in cache immediately after storing it.
  5. Storing entire collection with nested objects.
  6. Storing parent-child objects together and also separately.
  7. Caching Configuration settings.
  8. Caching Live Objects that has open handle to stream, file, registry, or network.
  9. Storing same item using multiple keys.
  10. Not updating or deleting items in cache after updating or deleting them on persistent storage.   

    http://www.codeproject.com/Articles/115107/Ten-Caching-Mistakes-that-Break-your-App

另外,在InfoQ里面的也有一篇相似的文章,提到的是

  1. 太过于依赖.NET默认的序列化机制
  2. 缓存大对象
  3. 使用缓存机制在线程间进行数据的共享
  4. 认为调用缓存API之后,数据会被立刻缓存起来
  5. 缓存大量的数据集合,而读取其中一部分
  6. 缓存大量具有图结构的对象导致内存浪费
  7. 缓存应用程序的配置信息
  8. 使用很多不同的键指向相同的缓存项
  9. 没有及时的更新或者删除再缓存中已经过期或者失效的数据

      http://www.infoq.com/cn/articles/misunderstanding-using-cache

 中西对照着看吧。

原文地址:https://www.cnblogs.com/liaotongquan/p/2821972.html