utkarshkukreti / markup.rs

A blazing fast, type-safe template engine for Rust.
Apache License 2.0
350 stars 14 forks source link

Add optional caching #6

Open pzmarzly opened 5 years ago

pzmarzly commented 5 years ago

In a project I'm working on, this decreases overall build time from between 8 and 10 to between 5 and 7 seconds.

ZaneHannanAU commented 5 years ago

Faster build time (considering my own is 10+ mins) is always good.

:+1:

utkarshkukreti commented 4 years ago

While a faster build time is good, I'm not sure about writing cached files into the user's system's cache directory. Is there any other popular crate which does this?

pzmarzly commented 4 years ago

Is there any other popular crate which does this?

I wasn't familiar with any, which is why I suggested it as an optional feature. Quick search on crates.io led me to gmp-mpfr-sys, which creates temporary files in ~/.cache/gmp-mpfr-sys, though it doesn't have to (it could use $OUT_DIR provided by cargo).

I was thinking about using target dir, but AFAIK we don't get any path to it. We would need to either:

a) assume it's $PWD/target - but it's sometimes not, b) assume it's $CARGO_MANIFEST_DIR/target - false in multi-crate projects, c) use $PWD to find a topmost directory that contains both Cargo.toml and target - which would work for 99% of use cases, but that 1% of users could get surprised

Many Rust developers already have large ~/.cargo/registry and ~/.cache/sccache dirs, so I thought writing few hundred KBs to ~/.cache wouldn't be that much of an issue if users were warned about that.

Kijewski commented 2 years ago

Cargo actually provides a per-crate temporary directory for such a use-case. You can have a look how I use caching in Nate: build.rs, generate.rs. (Actually I use it because then you have better error messages. The caching is only a by-product.)