Struct rocket_file_cache::CacheBuilder [] [src]

pub struct CacheBuilder { /* fields omitted */ }

A builder for Caches.

Methods

impl CacheBuilder
[src]

[src]

Create a new CacheBuilder.

[src]

Mandatory parameter. Sets the maximum number of bytes the cache can hold.

[src]

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()
    .size_limit_bytes(1024 * 1024 * 50) // 50 MB cache
    .priority_function(|access_count, size| {
        access_count * access_count * size
    })
    .build()
    .unwrap();

[src]

Set the minimum size in bytes for files that can be stored in the cache

[src]

Set the maximum size in bytes for files that can be stored in the cache

[src]

Finalize the cache.

Example

use rocket_file_cache::Cache;
use rocket_file_cache::CacheBuilder;

let cache: Cache = CacheBuilder::new()
    .size_limit_bytes(1024 * 1024 * 50) // 50 MB cache
    .min_file_size(1024 * 4) // Don't store files smaller than 4 KB
    .max_file_size(1024 * 1024 * 6) // Don't store files larger than 6 MB
    .build()
    .unwrap();

Trait Implementations

impl Debug for CacheBuilder
[src]

[src]

Formats the value using the given formatter.