Tkrzw
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
tkrzw::PageCache Class Referencefinal

Page cache for buffering I/O operations. More...

#include <tkrzw_file_util.h>

Public Types

typedef std::function< Status(int64_t off, void *buf, size_t size)> ReadType
 Type of callback function to read a clean buffer from the file. More...
 
typedef std::function< Status(int64_t off, const void *buf, size_t size)> WriteType
 Type of callback function to write a dirty buffer to the file. More...
 

Public Member Functions

 PageCache (int64_t page_size, int64_t capacity, ReadType read_func, WriteType write_func)
 Constructor. More...
 
 ~PageCache ()
 Destructor. More...
 
Status Read (int64_t off, void *buf, size_t size)
 Reads data. More...
 
Status Write (int64_t off, const void *buf, size_t size)
 Writes data. More...
 
Status Flush (int64_t off=0, int64_t size=0)
 Flushes all dirty buffers to the file. More...
 
void Clear ()
 Clear all data. More...
 
int64_t GetRegionSize ()
 Gets the region size used for reading. More...
 
void SetRegionSize (int64_t size)
 Sets the region size used for reading. More...
 

Static Public Attributes

static constexpr int32_t NUM_SLOTS = 16
 The number of slots for cuncurrency. More...
 

Detailed Description

Page cache for buffering I/O operations.

Member Typedef Documentation

◆ ReadType

typedef std::function<Status(int64_t off, void* buf, size_t size)> tkrzw::PageCache::ReadType

Type of callback function to read a clean buffer from the file.

◆ WriteType

typedef std::function<Status(int64_t off, const void* buf, size_t size)> tkrzw::PageCache::WriteType

Type of callback function to write a dirty buffer to the file.

Constructor & Destructor Documentation

◆ PageCache()

tkrzw::PageCache::PageCache ( int64_t  page_size,
int64_t  capacity,
ReadType  read_func,
WriteType  write_func 
)

Constructor.

Parameters
page_sizeThe page size of the I/O operation.
capacityThe capacity of the cache by the number of pages.
read_funcThe callback function to read a clean buffer from the file.
write_funcThe callback function to write a dirty buffer to the file.

◆ ~PageCache()

tkrzw::PageCache::~PageCache ( )

Destructor.

Member Function Documentation

◆ Read()

Status tkrzw::PageCache::Read ( int64_t  off,
void *  buf,
size_t  size 
)

Reads data.

Parameters
offThe offset of a source region.
bufThe pointer to the destination buffer.
sizeThe size of the data to be read.
Returns
The result status.

◆ Write()

Status tkrzw::PageCache::Write ( int64_t  off,
const void *  buf,
size_t  size 
)

Writes data.

Parameters
offThe offset of the destination region.
bufThe pointer to the source buffer.
sizeThe size of the data to be written.
Returns
The result status.

◆ Flush()

Status tkrzw::PageCache::Flush ( int64_t  off = 0,
int64_t  size = 0 
)

Flushes all dirty buffers to the file.

Parameters
offThe offset of the region to be synchronized.
sizeThe size of the region to be synchronized. If it is zero, the length to the end of file is specified.
Returns
The result status.

◆ Clear()

void tkrzw::PageCache::Clear ( )

Clear all data.

Dirty buffers are not written back.

◆ GetRegionSize()

int64_t tkrzw::PageCache::GetRegionSize ( )

Gets the region size used for reading.

Returns
The region size used for reading.

◆ SetRegionSize()

void tkrzw::PageCache::SetRegionSize ( int64_t  size)

Sets the region size used for reading.

Parameters
sizeThe region size used for reading.

Member Data Documentation

◆ NUM_SLOTS

constexpr int32_t tkrzw::PageCache::NUM_SLOTS = 16
staticconstexpr

The number of slots for cuncurrency.