Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ringfilecache.H File Reference

File-backed ring buffer cache for persistent storage. More...

#include <sys/time.h>
#include <stdio.h>
#include <cassert>
#include <string.h>
#include <stdexcept>
#include <memory>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <type_traits>
#include <ah-errors.H>
#include <tpl_array.H>
Include dependency graph for ringfilecache.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  RingFileCache< T >
 Persistent ring buffer cache with file-backed storage. More...
 
struct  RingFileCache< T >::Pars
 
class  RingFileCache< T >::Pointer
 Defines a pointer to a specific location in the cache. More...
 
class  RingFileCache< T >::Iterator
 

Variables

constexpr size_t Ring_Max_Name_Size = 4096
 Maximum length for cache filename in parameter file.
 

Detailed Description

File-backed ring buffer cache for persistent storage.

Provides a circular buffer cache that persists data to disk, enabling recovery after the program restarts. Ideal for caches that must survive crashes or for applications with memory constraints.

Features

  • Persistent storage: Cache survives program restarts
  • Ring buffer semantics: Fixed-size circular buffer (FIFO)
  • Fixed memory usage: Only cache metadata in RAM, data on disk
  • Binary serialization: Direct binary I/O for performance

Use Cases

  • Persistent LRU caches
  • Logging systems with bounded disk usage
  • Database write-ahead logs
  • Time-series data buffers

Requirements

  • Type T must be trivially copyable (no pointers/references)
  • Type T must be default constructible
Example
struct CacheEntry {
int key;
double value;
time_t timestamp;
};
RingFileCache<CacheEntry> cache("cache.dat", "cache.pars", 1000);
CacheEntry entry{42, 3.14, time(nullptr)};
cache.insert(entry);
CacheEntry retrieved;
if (cache.get(retrieved))
std::cout << "Retrieved: " << retrieved.key << '\n';
Persistent ring buffer cache with file-backed storage.
Author
Leandro Rabindranath León

Definition in file ringfilecache.H.

Variable Documentation

◆ Ring_Max_Name_Size

constexpr size_t Ring_Max_Name_Size = 4096
inlineconstexpr

Maximum length for cache filename in parameter file.

Definition at line 96 of file ringfilecache.H.

Referenced by RingFileCache< T >::create(), RingFileCache< T >::read_pars(), and RingFileCache< T >::test().