Git Product home page Git Product logo

rocket-file-cache's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rocket-file-cache's Issues

Get rid of Cache::new(). Either replace with default, or don't replace it at all.

Currently, Cache::new() makes some opinionated choices for the user, which should be covered by a Default impl instead.

By default:

  • The size should be unbounded.
  • No Min size
  • No Max size
  • Default priority function
  • Accesses per refresh should not be provided (never refresh).

Possibly a warning should be logged indicating that users of the method should use the builder instead.


Alternatively:

Don't replace it at all.
Force users to use the builder, which would have the same outcome as the Default impl anyways.

Have a refresh parameter

Expose a parameter in the cachebuilder that will allow consumers of the crate to specify that the cache should refresh a file every n accesses.

This should be useful in mitigating bit flips that will eventually accumulate in non ECC ram.

By default, this should not be active.

Changelog

Would you mind to add a CHANGELOG.md to the repo?

Make the Cache::get() method return a Result instead of an Option.

Consider implementing a custom Result that contains 3 variants:

  • CacheHit - file was found in the cache.
  • CacheMiss - File was not found in cache, but was found in the filesystem.
  • Err - File was not found in either the cache or the fs.

An ok() method could resolve this back to the existing Option, or this Err case could be rolled into the existing CachedFile implementation and would redirect to the 404 handler when responding, meaning that get() would return just a plain CachedFile.

Readme issues

Remove symbols around Intel processor specs.
Remove unneeded clone in the cache example block for the file path.

Create a cache-pool example

Mitigate Mutex lock contention by creating multiple caches that are pooled together.
If the number of threads is equal to the number of caches in the pool, then there should not be any latency waiting for locks.

That said, there would be an increase in memory consumption equal to the size of one cache times the number of caches in the pool.

Condense the file_map and file_stats_map

The stats for priority, access times, and size can be stored in the file_map alongside the files themselves.

This will simplify the implementation, while probably not having a significant impact on performance.

Limit number of files in the cache by their size

Currently the cache is limited by the number of files it can hold.
This should be changed to be limited by the total number of bytes the cache can hold.

This is an API breaking change, and should have high priority.

Provide a more explicit aging-out function.

Allow consumers of the crate to specify in the CacheBuilder a function that will execute every n accesses for the whole cache that will alter every file's access count and therefore priority.

Make the n an AtomicUsize. Given the ConcurrentHashmap implementation, it should be possible to iterate through all entries without depriving

Fix performance for cache misses.

Actually creating the in-memory file requires a copy.
Serializing the file to a request requires another copy.
That first copy should be avoided if possible.

So to bring cache misses more or less in parity with normal file reads do the following.

  • Get the size using https://doc.rust-lang.org/std/fs/struct.Metadata.html
  • Determine if an insertion is required using just the size and the path.
    • This will remove the required space.
  • If an insertion is required, then insert and return the sized file.
  • If not, get a file handle, similar to the NamedFile in Rocket and return that instead.
  • Return an Either<SizedFile,NamedFile> to be used in the CachedFile.

Also rename everything.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.