pub struct CacheBuilder { /* fields omitted */ }
Create a new CacheBuilder.
Sets the maximum number of bytes (as they exist in the FS) that the cache can hold.
The cache will take up more space in memory due to the backing concurrent HashMap it uses.
The memory overhead can be controlled by setting the concurrency parameter.
- size_limit - The number of bytes the cache will be able to hold.
Sets the concurrency setting of the concurrent hashmap backing the cache.
A higher concurrency setting allows more threads to access the hashmap at the expense of more memory use.
The default is 16.
Sets the number of times a file can be accessed from the cache before it will be refreshed from the disk.
By providing 1000, that will instruct the cache to refresh the file every 1000 times its accessed.
By default, the cache will not refresh the file.
This should be useful if you anticipate bitrot for the cache contents in RAM, as it will
refresh the file from the FileSystem, meaning that if there is an error in the cached data,
it will only be served for an average of n/2 accesses before the automatic refresh replaces it
with an assumed correct copy.
This function will panic if 0 is supplied.
This is to prevent 0 being used as a divisor in a modulo operation later.
Override the default priority function used for determining if the cache should hold a file.
By default a score is calculated using the square root of the size of a file, times the number
of times it was accessed.
Files with higher priority scores will be kept in the cache when files with lower scores are
added.
If there isn't room in the cache for two files, the one with the lower score will be removed /
won't be added.
The priority function should be kept simple, as it is calculated on every file in the cache
every time a new file is attempted to be added.
use rocket_file_cache::Cache;
use rocket_file_cache::CacheBuilder;
let cache: Cache = CacheBuilder::new()
.priority_function(|access_count, size| {
access_count * access_count * size
})
.build()
.unwrap();
Set the minimum size in bytes for files that can be stored in the cache
Set the maximum size in bytes for files that can be stored in the cache
Finalize the cache.
use rocket_file_cache::Cache;
use rocket_file_cache::CacheBuilder;
let cache: Cache = CacheBuilder::new()
.size_limit(1024 * 1024 * 50)
.min_file_size(1024 * 4)
.max_file_size(1024 * 1024 * 6)
.build()
.unwrap();
Formats the value using the given formatter. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
impl<T> Typeable for T where T: Any, | |
Get the TypeId
of this object.
impl<T> IntoCollection for T | |
Converts self
into a collection.
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where A: Array<Item = U>, F: FnMut(T) -> U, | |
impl<T, I> AsResult for T where I: Input, | |