VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Gv::Cache Class Reference

A queue of recent images that can be flushed to the filesystem on demand. More...

#include <gvcache.h>

Public Member Functions

 Cache (const G::Path &base_dir, const std::string &name, size_t size)
 Constructor. Paths are like "<base-dir>/.cache/<name>.123".
 
 ~Cache ()
 Destructor.
 
void store (const Gr::ImageBuffer &, const std::string &commit_path, const std::string &commit_path_other=std::string(), const std::string &same_as=std::string())
 Stores an image in the cache. More...
 
void commit (bool other=false)
 Commits all cached images to their non-cache location.
 
std::string base () const
 Returns the base directory, as passed to the constructor.
 

Detailed Description

A queue of recent images that can be flushed to the filesystem on demand.

The implementation keeps a large set of cache files open and re-writes them on a least-recently used basis. When a commit is requested the files are closed and moved into their proper place (see ImageOutput). By keeping the files open the images live in the kernel's buffer cache and do not need to hit the filesystem at all.

Definition at line 45 of file gvcache.h.

Member Function Documentation

void Gv::Cache::store ( const Gr::ImageBuffer image_buffer,
const std::string &  commit_path,
const std::string &  commit_path_other = std::string(),
const std::string &  same_as = std::string() 
)

Stores an image in the cache.

An alternate path for the committed file can be supplied, with the choice dictated by a parameter passed to commit().

The "same-as" path indicates where the image has already been saved to the filesystem, so a commit() just moves the already-saved file into place and discards the cached version. (In practice this avoids duplicates when recording in slow mode and then switching to fast mode with an associated flush of the cache.)

Definition at line 83 of file gvcache.cpp.


The documentation for this class was generated from the following files: