Overview
Theservice module runs as a Kodi background service when the plugin starts. It performs initialization tasks including cache clearing and provider prefetching to improve user experience.
Service Execution
The service runs automatically when Kodi loads the Cricfy plugin. It executes the following operations sequentially:1. Cache Clearing
Clears all cached data from the plugin’s cache storage using a wildcard pattern (
'%'). This ensures fresh data is fetched on plugin startup."cricfy_providers"- Cached provider list"channels_{hash}"- All cached channel lists (hashed by provider URL)- Any other cached entries
2. Provider Prefetching
Immediately fetches the provider list after clearing cache. This “warms up” the cache so providers are available instantly when the user opens the plugin UI.
- Faster UI Loading: Provider list is already cached when user navigates to plugin
- Early Error Detection: Network/decryption errors are caught during service initialization
- Background Operation: Happens without blocking Kodi’s UI
Code Structure
Execution Context
The service is configured inaddon.xml:
- When: Plugin is enabled/Kodi starts
- Thread: Background thread (non-blocking)
- Lifecycle: Runs once per Kodi session
Dependencies
| Module | Usage |
|---|---|
lib.config.cache | Cache management (delete operation) |
lib.logger.log_info | Logging service operations |
lib.providers.get_providers | Provider fetching and caching |
Logging
The service logs two events: 1. Cache Cleared:Use Cases
Fresh Start on Plugin Load
Every time the plugin loads, users get fresh data:- Updated provider list
- Latest channel information (fetched on demand)
- No stale cached content
Cache Warm-Up
Prefetching providers means:- Instant provider list display (no loading spinner)
- Better user experience
- Network requests happen in background
Example Scenario
User Action: Enable Cricfy plugin in Kodi Service Execution:- Provider list loads instantly (from warm cache)
- No network delay on first view
- Fresh data guaranteed
Performance Considerations
Trade-offs:
- Pro: Fast UI loading, fresh data on every startup
- Con: Network request on every Kodi/plugin restart
Error Handling
Customization
Developers can modify the service to: 1. Selective Cache Clearing:Related Modules
See also:- providers.mdx - Provider and channel fetching
- remote-config.mdx - API endpoint management
