pub struct VideoHashFilesystemCache(/* private fields */);Expand description
A disk-backed cache for hashes of videos on the filesystem. This is a utility struct for long term storage of VideoHashes. The cache tracks modification times of the underlying video files, and will automatically recalculate hashes based on this.
Cache entries are created and retrieved by calling fetch_update with the path to a video on disk. If there is no entry in the cache, or the modification time of the video is newer then the cache will create a video hash for the underlying file. If the video is already cached then the cache will supply its cached data
Hashes can be obtained from the cache without visiting the underlying video on the filesystem with fetch.
To update all hashes within a given directory (or set of directories) use update_using_fs
§A note on interior mutability
All methods on this struct and its underlying implementation are use interior mutability allow for operations to occur in parallel.
Implementations§
Source§impl VideoHashFilesystemCache
impl VideoHashFilesystemCache
Sourcepub fn new(
cache_save_thresold: u32,
cache_path: PathBuf,
) -> Result<Self, VdfCacheError>
pub fn new( cache_save_thresold: u32, cache_path: PathBuf, ) -> Result<Self, VdfCacheError>
Load a VideoHash cache from disk the specified path. If no cache exists at cache_path then a new cache will be created.
The cache will automatically save its contents to disk when cache_save_threshold write/delete operations have occurred to the cache.
Note: The cache does not automatically save its contents when it goes out of scope. You must manually call save after you have made the last modification to the chache contents.
Returns an error if it was not possible to load the cache or create a new one.
Sourcepub fn fetch(
&self,
src_path: impl AsRef<Path>,
) -> Result<VideoHash, VdfCacheError>
pub fn fetch( &self, src_path: impl AsRef<Path>, ) -> Result<VideoHash, VdfCacheError>
Fetch the hash for the video file at the given source path. If the cache does not already contain a hash
will not create one. This method does not read src_path on the filesystem.
Returns an error if the cache has no entry for src_path .
Sourcepub fn all_cached_paths(&self) -> Vec<PathBuf>
pub fn all_cached_paths(&self) -> Vec<PathBuf>
Get the paths of all VideoHashes stored in the cache.
Sourcepub fn fetch_update(
&self,
src_path: impl AsRef<Path>,
) -> Result<Option<Result<VideoHash, HashCreationErrorKind>>, VdfCacheError>
pub fn fetch_update( &self, src_path: impl AsRef<Path>, ) -> Result<Option<Result<VideoHash, HashCreationErrorKind>>, VdfCacheError>
If src_path has not been modified since it was cached, then return the cached hash.
If src_path has been deleted, then remove it from the cache and return None.
Otherwise create a new hash, insert it into the cache, and return it.
Returns an error if it was not possible to generate a hash from src_path.
Sourcepub fn save(&self) -> Result<(), VdfCacheError>
pub fn save(&self) -> Result<(), VdfCacheError>
Save the cache to disk.
Returns an error if it was not possible to write the cache to disk.
Sourcepub fn update_using_fs(
&self,
file_projection: &FileProjection,
) -> Result<Vec<VdfCacheError>, VdfCacheError>
pub fn update_using_fs( &self, file_projection: &FileProjection, ) -> Result<Vec<VdfCacheError>, VdfCacheError>
For all files on the filesystem matching file_projection, update the cache for all new or modified files.
Also, remove items from the cache if they no longer exist in the underlying filesystem.
§Return values
This function will return Err if any fatal error occurs. Otherwise, it returns a group
of nonfatal errors, typically a list of paths for which a VideoHash could not be generated.
§Fatal errors
- Unable to read any of the starting directories in
file_projection - Any Io error when reading/writing to the cache file itself.
§Nonfatal errors
- Failure to create a hash from any individual file.
- Failure to remove an item from the cache (This is unlikely and should only occur if calling this function more than once at the same time with overlapping paths)
§Parallelism
To speed up loading there is a cargo feature to allow hashes to be created from videos in parallel. Parallel loading is much faster than sequential loading but be aware that since Ffmpeg is already multithreaded this can use up a lot of CPU time.
Auto Trait Implementations§
impl !Freeze for VideoHashFilesystemCache
impl RefUnwindSafe for VideoHashFilesystemCache
impl Send for VideoHashFilesystemCache
impl Sync for VideoHashFilesystemCache
impl Unpin for VideoHashFilesystemCache
impl UnwindSafe for VideoHashFilesystemCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more