Skip to content

Commit ccb35e9

Browse files
committed
fix: turning off model cache now correctly keeps it untouched
1 parent bed2d12 commit ccb35e9

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

lua/parrot/chat_handler.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,8 +1243,9 @@ function ChatHandler:model(params)
12431243
local has_telescope, telescope = pcall(require, "telescope")
12441244

12451245
-- Get models with caching support
1246+
-- Note: model_cache_expiry_hours = 0 means "use cached models forever, don't fetch new"
12461247
local models
1247-
if prov:online_model_fetching() and self.options.model_cache_expiry_hours > 0 then
1248+
if prov:online_model_fetching() and self.options.model_cache_expiry_hours >= 0 then
12481249
local spinner = self.options.enable_spinner and Spinner:new(self.options.spinner_type) or nil
12491250
models = prov:get_available_models_cached(self.state, self.options.model_cache_expiry_hours, spinner)
12501251
else

lua/parrot/config.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ local defaults = {
231231
-- Refetch models (similar to setup logic, only for available providers)
232232
for _, prov_name in ipairs(providers_to_reload) do
233233
local _prov = require("parrot.provider").init_provider(vim.tbl_deep_extend("force", {name = prov_name}, parrot.providers[prov_name]))
234-
if _prov:online_model_fetching() and parrot.options.model_cache_expiry_hours > 0 then
234+
if _prov:online_model_fetching() and parrot.options.model_cache_expiry_hours >= 0 then
235235
local endpoint_hash = require("parrot.utils").generate_endpoint_hash(_prov)
236236
parrot.logger.info("Reloading model cache for " .. prov_name)
237237
local fresh_models = _prov:get_available_models_cached(state, parrot.options.model_cache_expiry_hours, spinner)
@@ -341,7 +341,8 @@ function M.setup(opts)
341341
local _prov = init_provider(provider_config)
342342

343343
-- Use cached model fetching if provider has model_endpoint
344-
if _prov:online_model_fetching() and M.options.model_cache_expiry_hours > 0 then
344+
-- Note: model_cache_expiry_hours = 0 means "use cached models forever, don't fetch new"
345+
if _prov:online_model_fetching() and M.options.model_cache_expiry_hours >= 0 then
345346
-- Check cache validity for this specific provider
346347
local endpoint_hash = utils.generate_endpoint_hash(_prov)
347348
local needs_update = not temp_state:is_cache_valid(prov_name, M.options.model_cache_expiry_hours, endpoint_hash)

lua/parrot/provider/multi_provider.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,20 +491,22 @@ end
491491
function MultiProvider:get_available_models_cached(state, cache_expiry_hours, spinner)
492492
-- Only use caching if model_endpoint is configured
493493
-- otherwise return fallback models
494-
if not self:online_model_fetching() and cache_expiry_hours == 0 then
494+
if not self:online_model_fetching() then
495495
return self.models
496496
end
497497

498498
-- Generate endpoint hash for cache validation
499499
local endpoint_hash = utils.generate_endpoint_hash(self)
500500

501501
-- Try to get from cache first
502+
-- Note: cache_expiry_hours = 0 means "never expire, use cached models forever"
502503
local cached_models = state:get_cached_models(self.name, cache_expiry_hours, endpoint_hash)
503504
if cached_models then
504505
return cached_models
505506
end
506507

507-
-- Cache miss or expired - fetch fresh models
508+
-- Cache miss or expired - fetch fresh models only if expiry > 0
509+
-- When cache_expiry_hours = 0, only fetch if no cache exists (first time setup)
508510
if spinner then
509511
spinner:start("Fetching models for " .. self.name .. "...")
510512
end

lua/parrot/state.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ function State:get_cached_models(provider, cache_expiry_hours, endpoint_hash)
229229
local expiry_seconds = cache_expiry_hours * 3600
230230

231231
-- Check if cache is expired
232-
if (now - cached.timestamp) > expiry_seconds then
232+
-- Note: cache_expiry_hours = 0 means "never expire" (keep cached models forever)
233+
if cache_expiry_hours > 0 and (now - cached.timestamp) > expiry_seconds then
233234
return nil
234235
end
235236

0 commit comments

Comments
 (0)