Skip to content

Comments

sxm.pl: persist channel list to disk cache with expiry and background refresh#70

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/save-channel-list-to-cache
Draft

sxm.pl: persist channel list to disk cache with expiry and background refresh#70
Copilot wants to merge 2 commits intomainfrom
copilot/save-channel-list-to-cache

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

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.json is 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() — derives channel_cache_file path (<cookie_dir>/channels.json), initialises channel_cache_expires, calls load_channel_cache() at construction time
  • load_channel_cache() — reads and validates channels.json on startup; if the cache is expired it still populates $self->{channels} so requests are served immediately and sets channel_cache_expires = 0 to trigger an immediate background refresh
  • save_channel_cache() — serialises the channel array with fetched_at/expires_at envelope; updates in-memory expiry
  • get_channels() — calls save_channel_cache() after every successful API fetch
  • refresh_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 retry
  • start_http_daemon() loop — wires refresh_channel_cache_if_expired() alongside the existing refresh_expired_playlists() / process_segment_queues() calls
Original prompt

This section details on the original issue you should resolve

<issue_title>Save channel list to cache</issue_title>
<issue_description>In the proxy sxm.pl

Save channel listing to the cache. Make sure its in a format where we know the expiry
Use the same folder we are using for cookies

Load the channel listing from cache on startup
Run a background event to refresh the cache when it expires. Do this asynchronously.
Continue to use and serve channel data until the new new channel data arrives.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

- 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
Copilot AI requested a review from paul-1 February 22, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Save channel list to cache

2 participants