refactor: generalize LruCache to support any key type (P5.16)

Made LruCache generic over key type K, not just UserId:
- LruCache<V> → LruCache<K, V>
- Added trait bounds: K: Eq + Hash + Clone + Copy
- Updated UserCache field types:
  * user_usernames: LruCache<UserId, String>
  * user_names: LruCache<UserId, String>
  * user_statuses: LruCache<UserId, UserOnlineStatus>

Benefits:
- Reusable cache implementation for any key types
- Type-safe caching
- No additional dependencies

Progress: Priority 5: 2/3 tasks, Total: 18/20 (90%)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Mikhail Kilin
2026-02-01 02:26:03 +03:00
parent 56bddabbe1
commit 67739583f3
3 changed files with 46 additions and 19 deletions

View File

@@ -728,12 +728,28 @@ open = { version = "5.0", optional = true }
---
### 16. LRU cache обобщение
### 16. LRU cache обобщение ✅ ЗАВЕРШЕНО
**Проблема**: Отдельные LRU кеши для `user_names` и `user_statuses`.
**Решение**: Создать обобщённый `LruCache<K, V>` или использовать готовый крейт `lru = "0.12"`.
**Реализовано**:
- ✅ Обобщённая структура `LruCache<K, V>` в `src/tdlib/users.rs`
- ✅ Type parameters:
- `K: Eq + Hash + Clone + Copy` — тип ключа
- `V: Clone` — тип значения
- ✅ Обновлена `UserCache`:
- `user_usernames: LruCache<UserId, String>`
- `user_names: LruCache<UserId, String>`
- `user_statuses: LruCache<UserId, UserOnlineStatus>`
-Все методы обобщены: `get()`, `peek()`, `insert()`, `contains_key()`, `len()`
**Преимущества**:
- ✅ Переиспользуемая реализация для любых типов ключей
- ✅ Type-safe кеширование
- ✅ Без дополнительных зависимостей
---
### 17. Tracing вместо println!
@@ -781,10 +797,11 @@ tracing-subscriber = "0.3"
- [x] P4.12 — Rustdoc ✅
- [x] P4.13 — Config validation ✅
- [x] P4.14 — Async/await consistency ✅
- [ ] Priority 5: 1/3 задач
- [ ] Priority 5: 2/3 задач
- [x] P5.15 — Feature flags ✅
- [x] P5.16 — LRU cache обобщение ✅
**Всего**: 17/20 задач (85%)
**Всего**: 18/20 задач (90%)
---