Page cache for buffering I/O operations.
More...
#include <tkrzw_file_util.h>
|
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.
|
|
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.
|
|
|
| PageCache (int64_t page_size, int64_t capacity, ReadType read_func, WriteType write_func) |
| Constructor.
|
|
| ~PageCache () |
| Destructor.
|
|
Status | Read (int64_t off, void *buf, size_t size) |
| Reads data.
|
|
Status | Write (int64_t off, const void *buf, size_t size) |
| Writes data.
|
|
Status | Flush (int64_t off=0, int64_t size=0) |
| Flushes all dirty buffers to the file.
|
|
void | Clear () |
| Clear all data.
|
|
int64_t | GetRegionSize () |
| Gets the region size used for reading.
|
|
void | SetRegionSize (int64_t size) |
| Sets the region size used for reading.
|
|
|
static constexpr int32_t | NUM_SLOTS = 16 |
| The number of slots for cuncurrency.
|
|
Page cache for buffering I/O operations.
◆ ReadType
Type of callback function to read a clean buffer from the file.
◆ WriteType
Type of callback function to write a dirty buffer to the file.
◆ PageCache()
tkrzw::PageCache::PageCache |
( |
int64_t | page_size, |
|
|
int64_t | capacity, |
|
|
ReadType | read_func, |
|
|
WriteType | write_func ) |
Constructor.
- Parameters
-
page_size | The page size of the I/O operation. |
capacity | The capacity of the cache by the number of pages. |
read_func | The callback function to read a clean buffer from the file. |
write_func | The callback function to write a dirty buffer to the file. |
◆ ~PageCache()
tkrzw::PageCache::~PageCache |
( |
| ) |
|
◆ Read()
Status tkrzw::PageCache::Read |
( |
int64_t | off, |
|
|
void * | buf, |
|
|
size_t | size ) |
Reads data.
- Parameters
-
off | The offset of a source region. |
buf | The pointer to the destination buffer. |
size | The 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
-
off | The offset of the destination region. |
buf | The pointer to the source buffer. |
size | The 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
-
off | The offset of the region to be synchronized. |
size | The 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
-
size | The region size used for reading. |
◆ NUM_SLOTS
int32_t tkrzw::PageCache::NUM_SLOTS = 16 |
|
staticconstexpr |
The number of slots for cuncurrency.