Skip to content

Commit d2d3b18

Browse files
rust-shed: add no-op cachelib_stub implementation to the shed
Reviewed By: StanislavGlebik Differential Revision: D20337902 fbshipit-source-id: 51adc6fa19ba22600be2fe543f4c14435cf9a01c
1 parent 1463ba7 commit d2d3b18

File tree

5 files changed

+423
-0
lines changed

5 files changed

+423
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"shed/async_compression",
66
"shed/async_unit",
77
"shed/bytes_ext",
8+
"shed/cachelib_stub",
89
"shed/chrome_trace",
910
"shed/cloned",
1011
"shed/codegen_includer_proc_macro",

shed/cachelib_stub/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "cachelib"
3+
edition = "2018"
4+
version = "0.1.0"
5+
authors = ['Facebook']
6+
license = "GPLv2+"
7+
include = ["src/**/*.rs"]
8+
9+
[dependencies]
10+
futures_ext = { path = "../futures_ext" }
11+
abomonation = "0.7"
12+
anyhow = "1.0"
13+
bytes = { version = "0.5", features = ["serde"] }
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This software may be used and distributed according to the terms of the
5+
* GNU General Public License found in the LICENSE file in the root
6+
* directory of this source tree.
7+
*/
8+
9+
use anyhow::{Error, Result};
10+
use futures_ext::BoxFuture;
11+
12+
use crate::lrucache::VolatileLruCachePool;
13+
14+
pub fn get_cached_or_fill<T, F>(
15+
_cache_pool: &VolatileLruCachePool,
16+
_cache_key: String,
17+
fetch: F,
18+
) -> BoxFuture<Option<T>, Error>
19+
where
20+
T: abomonation::Abomonation + Clone + Send + 'static,
21+
F: FnOnce() -> BoxFuture<Option<T>, Error>,
22+
{
23+
fetch()
24+
}
25+
26+
pub fn get_cached<T>(_cache_pool: &VolatileLruCachePool, _cache_key: &String) -> Result<Option<T>>
27+
where
28+
T: abomonation::Abomonation + Clone + Send + 'static,
29+
{
30+
Ok(None)
31+
}
32+
33+
/// Returns `false` if the entry could not be inserted (e.g. another entry with the same
34+
/// key was inserted first)
35+
pub fn set_cached<T>(
36+
_cache_pool: &VolatileLruCachePool,
37+
_cache_key: &String,
38+
_entry: &T,
39+
) -> Result<bool>
40+
where
41+
T: abomonation::Abomonation + Clone + Send + 'static,
42+
{
43+
Ok(false)
44+
}

shed/cachelib_stub/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This software may be used and distributed according to the terms of the
5+
* GNU General Public License found in the LICENSE file in the root
6+
* directory of this source tree.
7+
*/
8+
9+
#![deny(warnings)]
10+
11+
#[cfg(not(fbcode_build))]
12+
mod abomonation_future_cache;
13+
#[cfg(not(fbcode_build))]
14+
mod lrucache;
15+
16+
#[cfg(not(fbcode_build))]
17+
pub use crate::abomonation_future_cache::*;
18+
#[cfg(not(fbcode_build))]
19+
pub use crate::lrucache::*;
20+
21+
// export Abomonation so that users of this crate don't need to add abomination as dependency
22+
#[cfg(not(fbcode_build))]
23+
pub use abomonation::Abomonation;
24+
25+
#[cfg(fbcode_build)]
26+
pub use cachelib::*;

0 commit comments

Comments
 (0)