cache


A specialized memory device that provides read and write caching for a target device.

Library

IO<ToolKit>

Declaration

#include <ospace/io/cache.h>

class os_cache : public os_device

Enums

enum os_cache::limits
  {
  wbuf_size_limit = 4096,
  rbuf_size_limit = 4096
  };
  

Interface

Constructor
os_cache( const os_adapter& device , int wbuf , int rbuf )
Constructs a read/write cache for device using an internal write buffer of size wbuf (default os_cache::wbuf_size_limit ) bytes and an internal read buffer of size rbuf (default os_cache::rbuf_size_limit ) bytes.
Destructor
~os_cache()
Destroys this cache object after flushing its contents to the device.
(os_adapter)
operator os_adapter()
Returns the device adapter.
adapter
const os_adapter& adapter() const
Returns a constant reference to the device adapter.
bad
bool bad () const
Returns true if this device is in a bad state.
clear
void clear ()
Resets the state of this device.
close
bool close()
Returns true if this device successfully flushes the internal buffers and shuts down the chained device.
eof
bool eof () const
Returns true if this device is at EOF.
fail
bool fail () const
Returns true if this device is in a bad state or has reached EOF.
good
bool good() const
Returns true if this device is in a good state.
read
ssize_t read( const void* buffer , size_t bytes )
Reads up to the specified number of bytes of data into buffer from the cache or from the actual device if the cache is empty. Returns the number of bytes actually read or returns -1 if a failure occurs.
read_buffer_size
int read_buffer_size() const
Returns the size, in bytes, of the internal read buffer.
reset
void reset()
Resets the cache to a state as though it was just constructed..
seek
long seek( long offset , int seekdir )
Positions the cache and the chained device to be offset bytes from the position specified by seekdir ( os_device::begin , os_device::current , or os_device::end ). Returns the offset of the new position or returns -1 if the operation fails.
sync
bool sync()
Flushes the internal buffers of the cache and the chained device and returns true if successful.
write
ssize_t write( const void* buffer , size_t bytes )
Writes up to the specified number of bytes of data from buffer to the cache. Returns the number of bytes actually written or returns -1 if a failure occurs.
write_buffer_size
int write_buffer_size() const
Returns the size, in bytes, of the internal write buffer.

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.