Repository navigation
Refresh the cached model list when the host or API key changes - #102
Merged
dkotter merged 3 commits intoOct 28, 2026
Merged
Conversation
âĶdd a Refresh models button The model list is cached per provider for a day, so on sites with a persistent object cache a new host or API key kept showing the old models. Drop the cache when either setting is added, updated or deleted, and let the settings screen ask for a fresh list.
Collaborator
|
Seems reasonable if this isn't how things work, especially if its limiting what models the provider could select from when being used for some AI tasks on a WP site. |
dkotter
approved these changes
Oct 28, 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.
This PR proposes refreshing the cached Ollama model list when the host or API key changes, plus a Refresh models button on the settings screen (Fixes #82). We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/772. You can sign in with your GitHub ID to claim ownership of the project.
What was wrong.
listModelMetadata()goes through the client SDK'scached()helper, which stores the model list for 24 hours under a key built only from the directory class name. Nothing in the plugin ever calledinvalidateCaches(), so on a site with a persistent object cache, saving a new Host URL or a new API key on Settings > Connectors kept serving the old list. Deactivating or reinstalling the plugin does not clear the object cache either, which matches what the reporter tried. The empty-list hint ("pull a model and reload this page") had the same problem, since a reload serves the cached list again.What changed.
OllamaSettings::init()now hooksadd_option_,update_option_anddelete_option_for both the plugin's own settings option (Host URL) and the option core stores the Ollama API key in (OllamaSettings::API_KEY_OPTION_NAME) and calls a newinvalidate_model_cache(). That method callsinvalidateCaches()on the provider's model metadata directory, which also clears the in-memory/api/tagsresult added in #100. For the "maybe a button?" part of the issue, the AJAX handler acceptsrefresh=1, which drops the cache before listing, and the settings screen gets a Refresh models button that uses it.loadModels()now rebuilds its status element on each run so it can be called more than once, and the button is disabled while a request is in flight. Nothing changes for callers that don't passrefresh, and unrelated option saves leave the cache alone (there's a test for that).Reproduction at
developHEAD (2223d19). Running the realOllamaProvideragainst a mock transporter in the WP test suite, where the object cache lasts for the whole process like a persistent cache does:After
update_option()on the Ollama API key option and on the plugin's Host URL setting, the old list is still returned and Ollama is never asked again.Verification. The new
tests/Integration/Settings/OllamaSettingsModelCacheTest.phphas 10 tests covering key add/update/delete, host change, the AJAX handler with and withoutrefresh=1, an unrelated option save, and the case where the provider isn't registered. With theOllamaSettingschange reverted, 7 of them fail (5 assertion failures showing the stale list, and 2 on the missing method), while the three "stays cached" controls pass. With the change, the full PHPUnit suite goes from 145 to 155 tests, all passing, with the same 12 skipped. PHPCS, PHPStan,tsc --noEmit,wp-scripts lint-jsandwp-scripts buildare clean before and after. I checked the button in headless Chrome against the builtsettings.js, withapiFetchstubbed: it showed 3 models on the first load, and after the click it requestedâĶ&refresh=1, showed 1 model and re-enabled itself.How this was managed
This work was tracked as a story, https://eastagiletracker.com/projects/772/stories/982594, on a board imported from this repo's issues and pull requests (84 stories) at https://eastagiletracker.com/projects/772.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com