Skip to content

Commit 751ff51

Browse files
committed
Add mkdocs
1 parent 42103e7 commit 751ff51

File tree

13 files changed

+793
-22
lines changed

13 files changed

+793
-22
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: ci
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- main
7+
permissions:
8+
contents: write
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Configure Git Credentials
15+
run: |
16+
git config user.name github-actions[bot]
17+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: 3.x
21+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
22+
- uses: actions/cache@v4
23+
with:
24+
key: mkdocs-material-${{ env.cache_id }}
25+
path: .cache
26+
restore-keys: |
27+
mkdocs-material-
28+
- run: pip install mkdocs-material mkdocstrings[python]
29+
- run: mkdocs gh-deploy --force

.readthedocs.yaml

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/api.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# API Reference
2+
3+
## Main Cache Interface
4+
5+
::: fast_cache.FastAPICache
6+
options:
7+
show_source: true
8+
show_signature: true
9+
show_root_heading: true
10+
11+
## Backends
12+
::: fast_cache.InMemoryBackend
13+
options:
14+
show_source: true
15+
show_signature: true
16+
show_root_heading: true
17+
18+
::: fast_cache.RedisBackend
19+
options:
20+
show_source: true
21+
show_signature: true
22+
show_root_heading: true
23+
24+
::: fast_cache.PostgresBackend
25+
options:
26+
show_source: true
27+
show_signature: true
28+
show_root_heading: true
29+
::: fast_cache.MemcachedBackend
30+
options:
31+
show_source: true
32+
show_signature: true
33+
show_root_heading: true
34+
35+
## Backend Base Class
36+
37+
::: fast_cache.backends.backend.CacheBackend

docs/backends.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# 🗄️ Backends Overview
2+
3+
FastAPI Cachekit supports multiple cache backends, so you can choose the best fit for your application’s needs—whether you want blazing-fast in-memory caching for development, or distributed caching for production.
4+
5+
---
6+
7+
## Supported Backends
8+
9+
| Backend | Description | Best For | Docs |
10+
|--------------------|--------------------------------------------------|-------------------------|---------------------|
11+
| InMemoryBackend | Stores cache in the app’s memory (LRU support) | Development, testing | [In-Memory](backends/in_memory.md) |
12+
| RedisBackend | Uses Redis for distributed, production caching | Production, scaling | [Redis](backends/redis.md) |
13+
| PostgresBackend | Uses PostgreSQL for persistent SQL-based caching | Data persistence, SQL | [Postgres](backends/postgres.md) |
14+
| MemcachedBackend | Uses Memcached for high-speed distributed caching | High-speed, stateless | [Memcached](backends/memcached.md) |
15+
16+
---
17+
18+
## How to Choose a Backend
19+
20+
- **InMemoryBackend**
21+
- 🟢 Easiest to set up, no extra dependencies.
22+
- 🔴 Not shared between processes or servers.
23+
- 🔴 Data lost on restart.
24+
25+
- **RedisBackend**
26+
- 🟢 Distributed, scalable, and fast.
27+
- 🟢 Widely used in production.
28+
- 🔴 Requires a running Redis server.
29+
30+
- **PostgresBackend**
31+
- 🟢 Uses your existing PostgreSQL database.
32+
- 🟢 Data persists across restarts.
33+
- 🔴 Slightly slower than in-memory or Redis.
34+
35+
- **MemcachedBackend**
36+
- 🟢 High-speed, distributed, simple.
37+
- 🔴 No persistence (data lost on restart).
38+
- 🔴 No built-in authentication by default.
39+
40+
---
41+
42+
## Installation for Each Backend
43+
44+
See the [Installation Guide](installation.md) for details on installing optional dependencies for each backend.
45+
46+
---
47+
48+
## Backend Setup Guides
49+
50+
- [In-Memory Backend](backends/in_memory.md)
51+
- [Redis Backend](backends/redis.md)
52+
- [Postgres Backend](backends/postgres.md)
53+
- [Memcached Backend](backends/memcached.md)
54+
55+
---
56+
57+
## Adding More Backends
58+
59+
Want to add support for another backend?
60+
Open an issue or submit a pull request on [GitHub](https://github.com/devbijay/fast-cache)!
61+
62+
---
63+
64+
**FastAPI Cachekit makes it easy to switch backends with minimal code changes—just swap the backend class and you’re ready to go!**

docs/backends/in_memory.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# In-Memory Backend
2+
3+
The **InMemoryBackend** is the simplest backend for FastAPI Cachekit.
4+
It stores all cached data in the application's memory, making it ideal for local development, testing, or small-scale deployments.
5+
6+
---
7+
8+
## 🚀 Installation
9+
10+
No extra dependencies are required!
11+
The in-memory backend is **built-in** and works out of the box.
12+
13+
```bash
14+
pip install fastapi-cachekit
15+
```
16+
17+
---
18+
19+
## ⚙️ Setup with FastAPI
20+
21+
```python
22+
from fast_cache import FastAPICache, InMemoryBackend
23+
24+
cache = FastAPICache()
25+
backend = InMemoryBackend(namespace="myapp-cache")
26+
cache.init_app(app, backend)
27+
```
28+
29+
- `namespace` (optional): Prefix for all cache keys (default: `"fastapi-cache"`).
30+
31+
---
32+
33+
## 🧑‍💻 Example Usage
34+
35+
```python
36+
@app.get("/expensive")
37+
@cache.cached(expire=60)
38+
async def expensive_operation(x: int):
39+
# This result will be cached in memory for 60 seconds
40+
return {"result": x * 2}
41+
```
42+
43+
---
44+
45+
## 📝 Options
46+
47+
- **namespace**:
48+
A string prefix for all cache keys. Useful if you run multiple apps in the same process.
49+
50+
- **max_size** (optional):
51+
Maximum number of items to store in the cache.
52+
If set, the cache will evict the least recently used (LRU) items when full.
53+
54+
```python
55+
backend = InMemoryBackend(namespace="myapp-cache", max_size=1000)
56+
```
57+
58+
---
59+
60+
## ⚠️ Limitations
61+
62+
- **Not shared between processes or servers**:
63+
Each process has its own cache. Not suitable for distributed or multi-worker deployments.
64+
- **Data is lost on restart**:
65+
The cache is cleared when the app restarts.
66+
- **Best for development, testing, or single-process apps**.
67+
68+
---
69+
## 🔗 See Also
70+
71+
- [Backends Overview](../backends.md)
72+
- [API Reference](../api.md)
73+
- [Usage Guide](../usage.md)

docs/backends/memcached.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Memcached Backend
2+
3+
The **MemcachedBackend** allows you to use a Memcached server as a cache store for FastAPI Cachekit.
4+
This backend is ideal for high-speed, distributed caching in stateless applications.
5+
6+
---
7+
8+
## 🚀 Installation
9+
10+
Install FastAPI Cachekit with Memcached support:
11+
12+
```bash
13+
pip install fastapi-cachekit[memcached]
14+
```
15+
16+
Or with other tools:
17+
18+
- **uv**
19+
```bash
20+
uv add fastapi-cachekit[memcached]
21+
```
22+
- **poetry**
23+
```bash
24+
poetry add fastapi-cachekit -E memcached
25+
```
26+
27+
---
28+
29+
## ⚙️ Setup with FastAPI
30+
31+
```python
32+
from fast_cache import cache, MemcachedBackend
33+
34+
backend = MemcachedBackend(
35+
host="localhost",
36+
port=11211,
37+
namespace="myapp-cache"
38+
)
39+
cache.init_app(app, backend)
40+
```
41+
42+
- `host`: Memcached server host (default: `"localhost"`)
43+
- `port`: Memcached server port (default: `11211`)
44+
- `namespace`: Prefix for all cache keys (default: `"fastapi-cache"`)
45+
46+
---
47+
48+
## 🧑‍💻 Example Usage
49+
50+
```python
51+
@app.get("/expensive")
52+
@cache.cached(expire=60)
53+
async def expensive_operation(x: int):
54+
# This result will be cached in Memcached for 60 seconds
55+
return {"result": x * 2}
56+
```
57+
58+
---
59+
60+
## 📝 Options
61+
62+
- **host**:
63+
Memcached server host (default: `"localhost"`)
64+
65+
- **port**:
66+
Memcached server port (default: `11211`)
67+
68+
- **namespace**:
69+
String prefix for all cache keys (default: `"fastapi-cache"`)
70+
71+
72+
- **pool_size**:
73+
Maximum number of connections in the sync pool (default: `2`)
74+
75+
---
76+
77+
## ⚡️ Notes
78+
79+
- **Memcached is a high-speed, in-memory, distributed cache.**
80+
- **No persistence:** Data is lost if the server restarts.
81+
- **No built-in authentication by default:**
82+
SASL authentication is available if enabled on the server and configured in the backend.
83+
- **Best for stateless, high-throughput caching.**
84+
85+
---
86+
87+
## 🛠️ Example: Using SASL Authentication
88+
89+
If your Memcached server is configured with SASL:
90+
91+
```python
92+
backend = MemcachedBackend(
93+
host="localhost",
94+
port=11211,
95+
username="myuser",
96+
password="mypassword"
97+
)
98+
```
99+
100+
---
101+
102+
## 🔗 See Also
103+
104+
- [Backends Overview](../backends.md)
105+
- [API Reference](../api.md)
106+
- [Usage Guide](../usage.md)

0 commit comments

Comments
 (0)