sxm.pl: persist channel list to disk cache with expiry and background refresh#70
Draft
sxm.pl: persist channel list to disk cache with expiry and background refresh#70
Conversation
- Add CHANNEL_CACHE_TTL constant (24 hours) to SiriusXM package - Add File::Basename and File::Spec imports to SiriusXM package - Add channel_cache_file and channel_cache_expires fields to new() - Load channel cache from disk at startup via load_channel_cache() - New load_channel_cache(): reads channels.json, handles expired cache by still serving old data while scheduling immediate background refresh - New save_channel_cache(): persists channel list as JSON with fetched_at/expires_at envelope in the same dir as the cookie file - get_channels() now calls save_channel_cache() after successful API fetch - New refresh_channel_cache_if_expired(): background refresh that keeps old channel list available for serving during the refresh; retries in 5 minutes on failure - Wire refresh_channel_cache_if_expired() into start_http_daemon() loop Co-authored-by: paul-1 <6473457+paul-1@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Save channel list to cache and manage expiration
sxm.pl: persist channel list to disk cache with expiry and background refresh
Feb 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The proxy fetched the channel list from the SiriusXM API on every cold start and never persisted it, adding unnecessary latency and API calls. This adds a full cache lifecycle: save on fetch, load at startup, and async background refresh on expiry.
Cache format
channels.jsonis written to the same directory as the cookie file:{ "fetched_at": 1740000000, "expires_at": 1740086400, "channels": [ ... ] }Changes
CHANNEL_CACHE_TTL— new constant (86400 s / 24 h)SiriusXM::new()— deriveschannel_cache_filepath (<cookie_dir>/channels.json), initialiseschannel_cache_expires, callsload_channel_cache()at construction timeload_channel_cache()— reads and validateschannels.jsonon startup; if the cache is expired it still populates$self->{channels}so requests are served immediately and setschannel_cache_expires = 0to trigger an immediate background refreshsave_channel_cache()— serialises the channel array withfetched_at/expires_atenvelope; updates in-memory expiryget_channels()— callssave_channel_cache()after every successful API fetchrefresh_channel_cache_if_expired()— background refresh called from the server loop; keeps old channel list in place while fetching, falls back to old data on failure and schedules a 5-minute retrystart_http_daemon()loop — wiresrefresh_channel_cache_if_expired()alongside the existingrefresh_expired_playlists()/process_segment_queues()callsOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.