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
use TokenStream;
/// Defines a memoized query method, which stores
/// results of the method in a database cache store. Cached results are
/// keyed from the method name and arguments.
///
/// # Attributes
/// - `db`: (optional, expr) specify the value which should be used to get the
/// database instance. Defaults to `self`.
///
/// NOTE: the resulting expression **must** implement
/// [`lume_architect::DatabaseContext`].
///
/// Example:
/// ```rs
/// #[cached_query(db = self.db())]
/// ```
///
/// - `key`: (optional, expr) specify the value(s) which should be used to
/// create the cache key.
///
/// NOTE: the resulting expression **must** implement [`std::hash::Hash`].
///
/// Example:
/// ```rs
/// #[cached_query(key = self.id)]
/// ```
///
/// - `result`: (optional, boolean) specifies that the return type of the method
/// is a [`Result`], which should only be cached if the method returned
/// successfully.
///
/// Example:
/// ```rs
/// #[cached_query(result)]
/// ```
///
/// - `on_cycle`: (optional, expr) specifices how to handle queries which calls
/// themselves using the same arguments, creating an infinite loop. The
/// expression should be a closure, accepting a single argument of the
/// database instance.
///
/// Example:
/// ```rs
/// #[cached_query(on_cycle = { |_| String::from("default value") })]
/// ```