Struct rocket_file_cache::cache::Cache [] [src]

pub struct Cache { /* fields omitted */ }

The Cache holds a number of files whose bytes fit into its size_limit. The Cache acts as a proxy to the filesystem. When a request for a file is made, the Cache checks to see if it has a copy of the file. If it does have a file, it returns an Arc reference to the file in a format that can easily be serialized. If it doesn't own a copy of the file, it reads the file from the FS and tries to cache it. If there is room in the Cache, the cache will store the file, otherwise it will increment a count indicating the number of access attempts for the file.

When the cache is full, each file in the cache will have priority score determined by the priority function. When a a new file is attempted to be stored, it will calculate the priority of the new score and compare that against the score of the file with the lowest priority in the cache. If the new file's priority is higher, then the file in the cache will be removed and replaced with the new file. If removing the first file doesn't free up enough space for the new file, then the file with the next lowest priority will have its priority added to the other removed file's and the aggregate cached file's priority will be tested against the new file's.

This will repeat until either enough space can be freed for the new file, and the new file is inserted, or until the priority of the cached files is greater than that of the new file, in which case, the new file isn't inserted.

Methods

impl Cache
[src]

[src]

Creates a new Cache with the given size limit and the default priority function. The min and max file sizes are not set.

Arguments

  • size_limit - The number of bytes that the Cache is allowed to hold at a given time.

[src]

Either gets the file from the cache if it exists there, gets it from the filesystem and tries to cache it, or fails to find the file and returns None.

Arguments

  • pathbuf - A pathbuf that represents the path of the file in the filesystem. The pathbuf also acts as a key for the file in the cache. The path will be used to find a cached file in the cache or find a file in the filesystem if an entry in the cache doesn't exist.

[src]

If the a file has changed on disk, the cache will not automatically know that a change has occurred.

Calling this function will check if the file exists, read the new file into memory, replace the old file, and update the priority score to reflect the possibly new size of the file.

# Arguments

  • pathbuf - A pathbuf that represents the path of the file in the filesystem, and key in the cache. The path will be used to find the new file in the filesystem and find the old file to replace in the cache.

[src]

Removes the file from the cache. This will not reset the access count, so the next time the file is accessed, it will be added to the cache again. The access count will have to be reset separately.

Arguments

  • pathbuf - A pathbuf that acts as a key to the file that should be removed from the cache

Trait Implementations

impl Debug for Cache
[src]

[src]

Formats the value using the given formatter.