• cache和buffer的区别


    A buffer is just a container to hold data for a short period of time when more comes in at any given time than a consumer can use / process. It's a first-in, first-out situation - the data comes in, might be buffered, and goes out in the same order it came in, after a while.

    A cache is a storage for speeding up certain operations. Things get put in a cache, and should be retrieved from it multiple times, over and over again. There's no "flowing through the cache" kind of mechanism - data doesn't come in and go out in the same order - but it's just a holding container. The order might be anything, really - items are addressed via a key, they don't "flow through" but they are "put in" and stay there (until they're thrown out because of not being used, or because the system goes down).

    buffer中的数据是一次性的,主要是处理数据的速度不如数据到达的速度,当然也有其他原因(例如标准输入输出中的buffer则考虑的是减少系统调用)

    cache则是一种需要软件和硬件配合实现的机制,用于加快数据处理速度。

    总结一下:cache主要是存放最频繁访问的数据(例如根据程序的局部性原理,使用最近最少使用算法淘汰),buffer则主要考虑的是设备间的传输速度差距。

  • 相关阅读:
    多线程之 Final变量 详解
    多线程之 Volatile 变量 详解
    并发安全问题之HashMap
    探索设计模式目录
    MYsql 锁详解 锁 与索引的关系
    JVM GC 相关
    sql 注入 及 in 注入
    00
    03
    02
  • 原文地址:https://www.cnblogs.com/johnnyflute/p/3542850.html
Copyright © 2020-2023  润新知