Caching layer with pluggable backends (Redis, memory, PostgreSQL)
| Tier | infrastructure |
| Role | unclassified (baselined) |
| Path | crates/infrastructure/cache |
| Edition | 2021 |
| Targets | infrastructure_cache |
| Public items | 12 across 1 module |
| Tests | 8 |
What it is for
Caching layer with pluggable backends (Redis, memory).
Capabilities
crate root
Caching layer with pluggable backends (Redis, memory).
| Item |
|---|
pub const DEFAULT_TTL: Duration |
MemoryCache
In-memory cache backend using DashMap.
| Item |
|---|
pub struct MemoryCache |
MemoryCache :: fn default() -> Self |
MemoryCache :: fn new() -> Self |
MemoryCache :: fn len(& self) -> usize |
MemoryCache :: fn is_empty(& self) -> bool |
MemoryCache :: async fn get <T : DeserializeOwned + Send>(& self, key : & str) -> Result <Option <T>, CacheError> |
MemoryCache :: async fn set <T : Serialize + Send + Sync>(& self, key : & str, value : & T, ttl : Option <Duration>,) -> Result <(), CacheError> |
MemoryCache :: async fn delete(& self, key : & str) -> Result <(), CacheError> |
MemoryCache :: async fn exists(& self, key : & str) -> Result <bool, CacheError> |
MemoryCache :: async fn clear(& self) -> Result <(), CacheError> |
MemoryCache :: async fn get_or_set <T, F, Fut>(& self, key : & str, ttl : Option <Duration>, f : F,) -> Result <T, CacheError> where T : Serialize + DeserializeOwned + Send + Sync, F : FnOnce() -> Fut + Send, Fut : Future <Output = Result <T, CacheError>> + Send, |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
infrastructure_cache
memory
Public surface
`crate root`
| Item | What it is |
|---|---|
pub const DEFAULT_TTL: Duration | Default TTL for cache entries (1 hour). |
`memory`
| Item | What it is |
|---|---|
pub struct MemoryCache | In-memory cache backed by DashMap |
MemoryCache :: fn default() -> Self | — |
MemoryCache :: fn new() -> Self | Creates a new empty memory cache. |
MemoryCache :: fn len(& self) -> usize | Returns the number of entries in the cache |
MemoryCache :: fn is_empty(& self) -> bool | Returns true if the cache is empty. |
MemoryCache :: async fn get <T : DeserializeOwned + Send>(& self, key : & str) -> Result <Option <T>, CacheError> | — |
MemoryCache :: async fn set <T : Serialize + Send + Sync>(& self, key : & str, value : & T, ttl : Option <Duration>,) -> Result <(), CacheError> | — |
MemoryCache :: async fn delete(& self, key : & str) -> Result <(), CacheError> | — |
MemoryCache :: async fn exists(& self, key : & str) -> Result <bool, CacheError> | — |
MemoryCache :: async fn clear(& self) -> Result <(), CacheError> | — |
MemoryCache :: async fn get_or_set <T, F, Fut>(& self, key : & str, ttl : Option <Duration>, f : F,) -> Result <T, CacheError> where T : Serialize + DeserializeOwned + Send + Sync, F : FnOnce() -> Fut + Send, Fut : Future <Output = Result <T, CacheError>> + Send, | — |
Re-exports. Exported here, defined elsewhere.
| Export | Defined in |
|---|---|
CacheBackend | backend::CacheBackend |
CacheError | error::CacheError |
MemoryCache | memory::MemoryCache |
Boundary
Reaches into foundation.
Shares tier infrastructure with 82 other crates: infrastructure-acquire, infrastructure-adapters-google-calendar, infrastructure-adapters-google-gmail, infrastructure-adapters-google-places, infrastructure-adapters-google-trends, infrastructure-adapters-shodan, infrastructure-adapters-yelp, infrastructure-agent, … (82 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | infrastructure |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/infrastructure/cache |
| Vocabulary in force (lexicon) | current |
Tier flow. Which tiers this crate's own edges cross.
flowchart LR n_infrastructure["infrastructure"] --> n_foundation["foundation"]
Dependencies
Runtime, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `foundation-basemodels` | foundation | no | always |
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
async-trait | ^0.1 | — | no | always |
chrono | ^0.4 | serde | no | always |
dashmap | ^6 | — | no | always |
redis | ^0.27 | tokio-comp | yes | always |
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
sqlx | ^0.8 | runtime-tokio, postgres, chrono, uuid, json | no | always |
thiserror | ^2 | — | no | always |
tokio | ^1 | full | no | always |
uuid | ^1 | v4, v7, serde, js | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio-test | ^0.4 | — | no | always |
Build. None.
Depended on by. 1 workspace crate.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_application_cache["application-cache"] -->|uses| SELF SELF["infrastructure-cache"] SELF -->|runtime| n_foundation_basemodels["foundation-basemodels"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
| Feature | Enables | On by default |
|---|---|---|
default | — | yes |
redis | dep:redis | no |
flowchart LR n_default["default"] n_redis["redis"] --> n_dep_redis["dep:redis"]
Targets
| Kind | Name | Source |
|---|---|---|
| lib | infrastructure_cache | `src/lib.rs` |
Error model
No public error type was detected: no public item declares a type named *Error, and no public signature returns one.
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | yes |
| async runtime | yes |
| database access | yes |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
1 workspace crate depends on this one: application-cache.
Verification
| Kind | Count |
|---|---|
| Unit tests | 8 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 1 | 0 | 0 |
memory | 1 | 0 | 1 |
What the tests establish, by name:
test_memory_cache_clear—src/lib.rstest_memory_cache_complex_types—src/lib.rstest_memory_cache_delete—src/lib.rstest_memory_cache_exists—src/lib.rstest_memory_cache_get_missing_key—src/lib.rstest_memory_cache_get_or_set—src/lib.rstest_memory_cache_get_set—src/lib.rstest_memory_cache_ttl_expiration—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 5 | 12 |
Public modules with a //! block | 1 | 1 |
pie showData
title Public items with rustdoc
"Documented" : 5
"No rustdoc detected" : 7
Metrics
| Metric | Value |
|---|---|
| Rust source files | 4 |
| Source lines | 420 |
| Code lines | 272 |
| Public API items | 12 |
| Public modules | 1 |
| Tests | 8 |
| Examples | 0 |
| Cargo features | 2 |
| Direct runtime dependencies | 11 |
| Workspace reverse dependencies | 1 |
pie showData
title Public API by kind
"constant" : 1
"method" : 10
"struct" : 1
pie showData
title Rust source composition
"Code" : 272
"Blank or comment" : 148
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.