#ifndef CACHE_ENGINE_H
#define CACHE_ENGINE_H
struct cache_engine {
/*
* Allocate a `struct cache`-compatible struct and return it via cache_ptr.
*/
int (*fn_init) (struct cache_engine *, struct cache **);
/*
* Allocate a `struct cache_op`-compatible struct and return it via cache_ptr.
*
* Begin the index lookup.
*/
int (*fn_op_start) (struct cache *, struct cache_op **, struct cache_key *);
/*
* Return some information about the available data.
*/
int (*fn_op_available) (struct cache_op *op, size_t *size, size_t *offset);
/*
* Prepare to write and possibly read this cache entry.
*
* size_hint, if nonzero, provides a guess at the size of the cache entry that can be used to optimize stuff
*/
int (*fn_op_begin_write) (struct cache_op *, size_t size_hint);
/*
* Read some data from the given fd into this cache entry. Size may contain a non-zero value to hint at how many
* bytes should be read, or zero to just read a suitable amount. Should be updated to how many bytes were actually
* written (may be zero if writes are currently paused).
*/
int (*fn_op_push) (struct cache_op *op, int fd, size_t *size);
/*
* No more calls to fn_op_push will take place. The cache entry now contains the complete data.
*/
int (*fn_op_done) (struct cache_op *op);
/*
* The op is not needed for any operations anymore. Free any resources and memory associated with this op,
* including the op itself.
*/
int (*fn_op_close) (struct cache_op *op);
};
#endif /* CACHE_ENGINE_H */