This repository has been archived by the owner on Sep 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcache_store.rs
60 lines (49 loc) · 1.56 KB
/
cache_store.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use futures::{Future, Stream};
use std::io;
use crate::cache_store_notifier::{CacheOperation, CacheStoreNotifierError};
pub type CacheStream = Box<Stream<Item = Vec<u8>, Error = CacheError> + Send>;
pub type EmptyCacheFuture = Box<Future<Item = (), Error = CacheError> + Send>;
pub trait CacheStore {
fn get(&self, key: String) -> Box<Future<Item = Option<CacheEntry>, Error = CacheError> + Send>;
fn set(
&self,
key: String,
data_stream: Box<Stream<Item = Vec<u8>, Error = ()> + Send>,
opts: CacheSetOptions,
) -> EmptyCacheFuture;
fn del(&self, key: String) -> EmptyCacheFuture;
fn expire(&self, key: String, ttl: u32) -> EmptyCacheFuture;
fn ttl(&self, key: String) -> Box<Future<Item = i32, Error = CacheError> + Send>;
fn purge_tag(&self, tag: String) -> EmptyCacheFuture;
fn set_tags(&self, key: String, tags: Vec<String>) -> EmptyCacheFuture;
fn notify(
&self,
op: CacheOperation,
value: String,
) -> Box<Future<Item = (), Error = CacheStoreNotifierError> + Send>;
fn set_meta(&self, key: String, meta: String) -> EmptyCacheFuture;
}
#[derive(Debug)]
pub enum CacheError {
Unknown,
NotFound,
Failure(String),
IoErr(io::Error),
}
#[derive(Debug)]
pub struct CacheSetOptions {
pub ttl: Option<u32>,
pub tags: Option<Vec<String>>,
pub meta: Option<String>,
}
pub struct CacheEntry {
pub meta: Option<String>,
pub stream: CacheStream,
}
impl From<io::Error> for CacheError {
#[inline]
fn from(err: io::Error) -> CacheError {
CacheError::IoErr(err)
}
}
pub type CacheResult<T> = Result<T, CacheError>;