@@ -4,7 +4,7 @@ local utils = require("mona.utils")
44-- Cache configuration
55M .config = {
66 cache_file = nil , -- Will be set in M.get_cache_file()
7- default_ttl = 300 -- 5 minutes default TTL
7+ default_ttl = 300 , -- 5 minutes default TTL
88}
99
1010-- Get cache file path
@@ -14,11 +14,11 @@ M.get_cache_file = function()
1414 M .config .cache_file = vim .fn .stdpath (" cache" ) .. " /mona_nvim_cache.json"
1515 else
1616 -- Fallback for testing
17- local home = (vim and vim .env and vim .env .HOME ) or
18- (vim and vim .env and vim .env .USERPROFILE ) or
19- os.getenv and os.getenv (" HOME" ) or
20- os.getenv and os.getenv (" USERPROFILE" ) or
21- " /tmp"
17+ local home = (vim and vim .env and vim .env .HOME )
18+ or (vim and vim .env and vim .env .USERPROFILE )
19+ or os.getenv and os.getenv (" HOME" )
20+ or os.getenv and os.getenv (" USERPROFILE" )
21+ or " /tmp"
2222 M .config .cache_file = home .. " /.mona_nvim_cache.json"
2323 end
2424 end
@@ -34,7 +34,7 @@ M.load = function()
3434 if cache_loaded then
3535 return
3636 end
37-
37+
3838 local cache_file = M .get_cache_file ()
3939 if vim .fn and vim .fn .filereadable and vim .fn .filereadable (cache_file ) == 1 then
4040 local ok , content = pcall (vim .fn .readfile , cache_file )
@@ -46,7 +46,7 @@ M.load = function()
4646 end
4747 end
4848 end
49-
49+
5050 cache_loaded = true
5151end
5252
@@ -57,7 +57,7 @@ M.save = function()
5757 local cache_dir = vim .fn .fnamemodify (cache_file , " :h" )
5858 utils .safe_mkdir (cache_dir , false )
5959 end
60-
60+
6161 if vim .fn and vim .fn .json_encode then
6262 local ok , json = pcall (vim .fn .json_encode , cache )
6363 if ok then
6969-- Get value from cache
7070M .get = function (key )
7171 M .load ()
72-
72+
7373 local entry = cache [key ]
7474 if not entry then
7575 return nil
7676 end
77-
77+
7878 -- Check expiration
7979 if entry .expires and entry .expires < os.time () then
8080 cache [key ] = nil
8181 return nil
8282 end
83-
83+
8484 return entry .value
8585end
8686
8787-- Set value in cache
8888M .set = function (key , value , ttl )
8989 M .load ()
90-
90+
9191 cache [key ] = {
9292 value = value ,
9393 expires = ttl and (os.time () + ttl ) or nil ,
94- created = os.time ()
94+ created = os.time (),
9595 }
96-
96+
9797 M .save ()
9898end
9999
100100-- Remove value from cache
101101M .delete = function (key )
102102 M .load ()
103-
103+
104104 cache [key ] = nil
105105 M .save ()
106106end
107107
108108-- Clear expired entries
109109M .clean = function ()
110110 M .load ()
111-
111+
112112 local now = os.time ()
113113 local cleaned = false
114-
114+
115115 for key , entry in pairs (cache ) do
116116 if entry .expires and entry .expires < now then
117117 cache [key ] = nil
118118 cleaned = true
119119 end
120120 end
121-
121+
122122 if cleaned then
123123 M .save ()
124124 end
@@ -133,28 +133,28 @@ end
133133-- Get cache statistics
134134M .stats = function ()
135135 M .load ()
136-
136+
137137 local total = 0
138138 local expired = 0
139139 local now = os.time ()
140-
140+
141141 for _ , entry in pairs (cache ) do
142142 total = total + 1
143143 if entry .expires and entry .expires < now then
144144 expired = expired + 1
145145 end
146146 end
147-
147+
148148 local file_size = 0
149149 if vim .fn and vim .fn .getfsize then
150150 file_size = vim .fn .getfsize (M .get_cache_file ())
151151 end
152-
152+
153153 return {
154154 total = total ,
155155 expired = expired ,
156156 active = total - expired ,
157- file_size = file_size
157+ file_size = file_size ,
158158 }
159159end
160160
@@ -164,21 +164,21 @@ M.keys = {
164164 font_installed = function (family , font_type )
165165 return string.format (" font:installed:%s:%s" , family or " all" , font_type or " default" )
166166 end ,
167-
167+
168168 -- Font version
169169 font_version = function ()
170170 return " font:version:latest"
171171 end ,
172-
172+
173173 -- Terminal detection
174174 terminal_type = function ()
175175 return " terminal:detected"
176176 end ,
177-
177+
178178 -- Font file paths
179179 font_files = function (family )
180180 return string.format (" font:files:%s" , family )
181- end
181+ end ,
182182}
183183
184- return M
184+ return M
0 commit comments