KaykCaputo / KaykCaputo/OpenCifra

Add local caching for viewed songs

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
enhancement feature
Dominant language
Python
Stars
6
Forks
1
PR merge metrics
No merged PRs in 30d

Description

## Description
Currently, every time a user views a song, the app fetches it from the internet. Implementing local caching would improve performance and enable offline access to previously viewed songs.

## Benefits
- Faster load times for repeat views
- Reduced bandwidth usage
- Offline access to cached songs
- Better user experience

## Proposed Implementation
Use a simple JSON-based cache:

```python
import json
import hashlib
from pathlib import Path

class SongCache:
def __init__(self, cache_dir=".cache"):
self.cache_dir = Path(cache_dir)
self.cache_dir.mkdir(exist_ok=True)

def get_cache_key(self, title, artist):
return hashlib.md5(f"{title}_{artist}".encode()).hexdigest()

def get(self, title, artist):
cache_file = self.cache_dir / f"{self.get_cache_key(title, artist)}.json"
if cache_file.exists():
return json.loads(cache_file.read_text())
return None

def set(self, title, artist, content):
cache_file = self.cache_dir / f"{self.get_cache_key(title, artist)}.json"
cache_file.write_text(json.dumps({
"title": title,
"artist": artist,
"content": content
}))
```

## Additional Features
- Cache expiration (e.g., 30 days)
- Cache size management
- Manual cache clearing option in settings
- Cache statistics display

Contributor guide

No contributing guide indexed for this repository

Research direction

No files, tests, or entry points are named. First locate the song-view fetch flow and the settings implementation, then determine how cached content should be integrated. Done means previously viewed songs can be loaded locally, with the proposed expiration, size management, clearing option, and statistics addressed or explicitly scoped.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
mobile, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.