Skip to content

Commit 2d5bad6

Browse files
docs: add caching docs
1 parent 8d544c5 commit 2d5bad6

File tree

4 files changed

+51
-20
lines changed

4 files changed

+51
-20
lines changed

README.md

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,40 @@ manga = enma.random()
102102
print(manga)
103103
```
104104

105+
## Caching
106+
Caching is a key feature in Enma that improves your application's efficiency by storing the results of data requests. This means when the same data is requested again, Enma can quickly retrieve it from the cache instead of repeatedly calling the external source. This results in faster response times and less strain on both your application and the external APIs.
107+
108+
### How Caching Benefits You
109+
- **Speed**: Retrieving data from the cache is faster than making a new request to a manga repository.
110+
- **Efficiency**: Reduces the number of network requests, which is especially useful when dealing with rate-limited APIs.
111+
- **Reliability**: Provides more consistent application performance even with varying network conditions.
112+
113+
### Customizing Cache Settings
114+
While Enma provides default caching settings that suit most needs, you may want to customize these settings based on your specific requirements, like how often you expect data to change or specific API rate limits.
115+
116+
#### Adjusting Cache Duration via Environment Variables
117+
You can control how long data is kept in the cache by setting environment variables. This allows you to fine-tune the balance between data freshness and retrieval speed without modifying the core library code.
118+
119+
For example, to change the cache expiration for fetching chapters, you can set the `ENMA_CACHING_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS` environment variable:
120+
121+
```sh
122+
# Sets the cache duration to 30 minutes
123+
export ENMA_CACHING_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS=1800
124+
```
125+
126+
This customization capability ensures that you can adapt the caching behavior to best fit your application's performance and efficiency needs.
127+
128+
By leveraging caching, Enma helps make your manga-related applications faster and more reliable, all while giving you the flexibility to tailor caching behavior as needed.
129+
130+
#### Available Caching TTL Settings
131+
| KEY | DEFAULT |
132+
|------------------------------------------------|---------|
133+
| ENMA_CACHING_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS| 100 |
134+
| ENMA_CACHING_PAGINATE_TTL_IN_SECONDS | 100 |
135+
| ENMA_CACHING_SEARCH_TTL_IN_SECONDS | 100 |
136+
| ENMA_CACHING_GET_TTL_IN_SECONDS | 300 |
137+
| ENMA_CACHING_AUTHOR_TTL_IN_SECONDS | 100 |
138+
105139
## Downloading Chapters
106140
Using Enma you're able to download chapter pages to your local storage or any other storage that implements `ISaverAdapter`.
107141

@@ -150,23 +184,6 @@ enma = Enma()
150184
enma.source_manager.set_source('manganato')
151185
doujin = enma.get(identifier='manga-kb951984', with_symbolic_links=True)
152186

153-
# Manga(id='manga-kb951984',
154-
# created_at=datetime.datetime(2024, 1, 22, 10, 5),
155-
# updated_at=datetime.datetime(2024, 1, 22, 10, 5),
156-
# title=Title(english='Monster Musume No Iru Nichijou',
157-
# japanese='モンスター娘のいる日常',
158-
# other='魔物娘的同居日常'),
159-
# language=None,
160-
# cover=Image(uri='https://avt.mkklcdnv6temp.com/23/p/1-1583464626.jpg', name='image.jpg', width=0, height=0, mime=<MIME.J: 'jpg'>),
161-
# thumbnail=Image(uri='https://avt.mkklcdnv6temp.com/23/p/1-1583464626.jpg', name='image.jpg', width=0, height=0, mime=<MIME.J: 'jpg'>),
162-
# authors=[Author(name='Okayado', id=0)],
163-
# genres=[Genre(name='Comedy', id=0),
164-
# Genre(name='Fantasy', id=0),
165-
# Genre(name='Harem', id=0)],
166-
# chapters=[Chapter(id='chapter-84', pages=[], pages_count=0, link=SymbolicLink(link='https://chapmanganato.to/manga-kb951984/chapter-84')),
167-
# Chapter(id='chapter-83', pages=[], pages_count=0, link=SymbolicLink(link='https://chapmanganato.to/manga-kb951984/chapter-83'))],
168-
# chapters_count=95)
169-
170187
if doujin is not None:
171188
chapter_ref = doujin.chapters[0]
172189
chapter = enma.fetch_chapter_by_symbolic_link(link=chapter_ref.link)
@@ -232,6 +249,23 @@ While using the library, you might encounter some specific errors. Here's a desc
232249
- **Description**: Raised when trying to perform an action with an invalid data type.
233250
- **Common Cause**: Making an action with wrong parameter data type.
234251

252+
7. **Unknown**:
253+
- **Description**: Raised when was not possible to determine the error root cause.
254+
- **Common Cause**: Not properly handled error.
255+
256+
7. **NotFound**:
257+
- **Description**: Raised when was not possible to find the requested resource..
258+
- **Common Cause**: Fetching an inexistent resource.
259+
260+
7. **Forbidden**:
261+
- **Description**: Raised when trying to perform a request to the source without right credentials.
262+
- **Common Cause**: Making a request with no or invalid credentials.
263+
264+
7. **ExceedRateLimit**:
265+
- **Description**: Raised when trying to perform more requests than a server can handle.
266+
- **Common Cause**: Looping through many pages without cooling down.
267+
268+
235269
When encountering one of these errors, refer to the description and common cause to assist in troubleshooting.
236270

237271
## Future Plans

enma/domain/entities/author_page.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
This module defines the SearchResult entity for the Enma application.
33
It represents the result of a manga search operation.
44
"""
5-
from dataclasses import dataclass
65
from datetime import datetime
76
from typing import TypedDict, Union
87
from enma.domain.entities.manga import Manga

enma/domain/entities/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
T = TypeVar('T')
66

7-
87
class Entity(Generic[T]):
98
"""Base class for entities in the domain model.
109

enma/domain/entities/search_result.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
This module defines the SearchResult entity for the Enma application.
33
It represents the result of a manga search operation.
44
"""
5-
from dataclasses import dataclass
65
from datetime import datetime
76
from typing import TypedDict, Union
87
from enma.domain.entities.manga import Manga

0 commit comments

Comments
 (0)