A method,
system, apparatus, and computer-readable medium are provided for implementing caching in a
data storage system. According to aspects of the invention, a cache module is provided that utilizes cache lines sized according to a snapshot chunk size or an allocation
unit size. The cache module utilizes cache header data structures corresponding to cache lines, each of which is assigned a device and logical block access range when active. The active headers are arranged in a set of hash queues. A free
queue corresponds to the
list of unused cache headers and a dirty
queue corresponding to a
list of unflushed cache headers. The cache header contains sector-level bitmaps of the cache line, specifying on a per sector
granularity the bits that are dirty and valid. Flushing is performed by
copying the dirty
bitmap into a temporary memory location and flushing the bits set in it, while resetting the dirty
bitmap and allowing writes to it. A read-ahead
algorithm is used to perform read-ahead operations only in the event of a sequential read.