Fossil SCM

Improvements to the "fossil cache" command.

drh 2021-06-16 01:10 trunk
Commit e0ebe6f0338825affb13e19d3f9c2af96c292ca73308a5d7dc38d7e9ec03cfbd
1 file changed +46 -14
+46 -14
--- src/cache.c
+++ src/cache.c
@@ -197,10 +197,17 @@
197197
sqlite3_finalize(pStmt);
198198
sqlite3_exec(db, rc ? "COMMIT" : "ROLLBACK", 0, 0, 0);
199199
sqlite3_close(db);
200200
}
201201
202
+/*
203
+** SETTING: max-cache-entry width=10 default=10
204
+**
205
+** This is the maximum number of entries to allow in the web-cache
206
+** for tarballs, ZIP-archives, and SQL-archives.
207
+*/
208
+
202209
/*
203210
** Attempt to read content out of the cache with the given zKey. Return
204211
** non-zero on success and zero if unable to locate the content.
205212
**
206213
** Possible reasons for returning zero:
@@ -262,10 +269,12 @@
262269
** init Create the cache file if it does not already exist.
263270
**
264271
** list|ls List the keys and content sizes and other stats for
265272
** all entries currently in the cache.
266273
**
274
+** size ?N? Query or set the maximum number of entries in the cache.
275
+**
267276
** status Show a summary of the cache status.
268277
**
269278
** The cache is stored in a file that is distinct from the repository
270279
** but that is held in the same directory as the repository. The cache
271280
** file can be deleted in order to completely disable the cache.
@@ -303,12 +312,14 @@
303312
sqlite3_close(db);
304313
fossil_print("cache cleared\n");
305314
}else{
306315
fossil_print("nothing to clear; cache does not exist\n");
307316
}
308
- }else if(( strncmp(zCmd, "list", nCmd)==0 )
309
- || ( strncmp(zCmd, "ls", nCmd)==0 )){
317
+ }else if( strncmp(zCmd, "list", nCmd)==0
318
+ || strncmp(zCmd, "ls", nCmd)==0
319
+ || strncmp(zCmd, "status", nCmd)==0
320
+ ){
310321
db = cacheOpen(0);
311322
if( db==0 ){
312323
fossil_print("cache does not exist\n");
313324
}else{
314325
int nEntry = 0;
@@ -319,29 +330,43 @@
319330
" FROM cache"
320331
" ORDER BY tm DESC"
321332
);
322333
if( pStmt ){
323334
while( sqlite3_step(pStmt)==SQLITE_ROW ){
324
- fossil_print("%s %4d %8s %s\n",
325
- sqlite3_column_text(pStmt, 3),
326
- sqlite3_column_int(pStmt, 2),
327
- sqlite3_column_text(pStmt, 1),
328
- sqlite3_column_text(pStmt, 0));
335
+ if( zCmd[0]=='l' ){
336
+ fossil_print("%s %4d %8s %s\n",
337
+ sqlite3_column_text(pStmt, 3),
338
+ sqlite3_column_int(pStmt, 2),
339
+ sqlite3_column_text(pStmt, 1),
340
+ sqlite3_column_text(pStmt, 0));
341
+ }
329342
nEntry++;
330343
}
331344
sqlite3_finalize(pStmt);
332345
}
333346
sqlite3_close(db);
334
- fossil_print("Entries: %d Cache-file Size: %lld\n",
335
- nEntry, file_size(zDbName, ExtFILE));
347
+ fossil_print(
348
+ "Filename: %s\n"
349
+ "Entries: %d\n"
350
+ "max-cache-entry: %d\n"
351
+ "Cache-file Size: %,lld\n",
352
+ zDbName,
353
+ nEntry,
354
+ db_get_int("max-cache-entry",10),
355
+ file_size(zDbName, ExtFILE)
356
+ );
336357
fossil_free(zDbName);
337358
}
338
- }else if( strncmp(zCmd, "status", nCmd)==0 ){
339
- fossil_print("TBD...\n");
359
+ }else if( strncmp(zCmd, "size", nCmd)==0 ){
360
+ if( g.argc>=4 ){
361
+ int n = atoi(g.argv[3]);
362
+ if( n>=5 ) db_set_int("max-cache-entry",n,0);
363
+ }
364
+ fossil_print("max-cache-entry: %d\n", db_get_int("max-cache-entry",10));
340365
}else{
341366
fossil_fatal("Unknown subcommand \"%s\"."
342
- " Should be one of: clear init list status", zCmd);
367
+ " Should be one of: clear init list size status", zCmd);
343368
}
344369
}
345370
346371
/*
347372
** WEBPAGE: cachestat
@@ -380,12 +405,19 @@
380405
sqlite3_finalize(pStmt);
381406
@ </ol>
382407
}
383408
zDbName = cacheName();
384409
bigSizeName(sizeof(zBuf), zBuf, file_size(zDbName, ExtFILE));
385
- @ <p>cache-file name: %h(zDbName)</p>
386
- @ <p>cache-file size: %s(zBuf)</p>
410
+ @ <p>
411
+ @ cache-file name: %h(zDbName)<br>
412
+ @ cache-file size: %s(zBuf)<br>
413
+ @ max-cache-entry: %d(db_get_int("max-cache-entry",10))
414
+ @ </p>
415
+ @ <p>
416
+ @ Use the "<a href="%R/help?cmd=cache">fossil cache</a>" command
417
+ @ on the command-line to create and configure the web-cache.
418
+ @ </p>
387419
fossil_free(zDbName);
388420
sqlite3_close(db);
389421
}
390422
style_finish_page();
391423
}
392424
--- src/cache.c
+++ src/cache.c
@@ -197,10 +197,17 @@
197 sqlite3_finalize(pStmt);
198 sqlite3_exec(db, rc ? "COMMIT" : "ROLLBACK", 0, 0, 0);
199 sqlite3_close(db);
200 }
201
 
 
 
 
 
 
 
202 /*
203 ** Attempt to read content out of the cache with the given zKey. Return
204 ** non-zero on success and zero if unable to locate the content.
205 **
206 ** Possible reasons for returning zero:
@@ -262,10 +269,12 @@
262 ** init Create the cache file if it does not already exist.
263 **
264 ** list|ls List the keys and content sizes and other stats for
265 ** all entries currently in the cache.
266 **
 
 
267 ** status Show a summary of the cache status.
268 **
269 ** The cache is stored in a file that is distinct from the repository
270 ** but that is held in the same directory as the repository. The cache
271 ** file can be deleted in order to completely disable the cache.
@@ -303,12 +312,14 @@
303 sqlite3_close(db);
304 fossil_print("cache cleared\n");
305 }else{
306 fossil_print("nothing to clear; cache does not exist\n");
307 }
308 }else if(( strncmp(zCmd, "list", nCmd)==0 )
309 || ( strncmp(zCmd, "ls", nCmd)==0 )){
 
 
310 db = cacheOpen(0);
311 if( db==0 ){
312 fossil_print("cache does not exist\n");
313 }else{
314 int nEntry = 0;
@@ -319,29 +330,43 @@
319 " FROM cache"
320 " ORDER BY tm DESC"
321 );
322 if( pStmt ){
323 while( sqlite3_step(pStmt)==SQLITE_ROW ){
324 fossil_print("%s %4d %8s %s\n",
325 sqlite3_column_text(pStmt, 3),
326 sqlite3_column_int(pStmt, 2),
327 sqlite3_column_text(pStmt, 1),
328 sqlite3_column_text(pStmt, 0));
 
 
329 nEntry++;
330 }
331 sqlite3_finalize(pStmt);
332 }
333 sqlite3_close(db);
334 fossil_print("Entries: %d Cache-file Size: %lld\n",
335 nEntry, file_size(zDbName, ExtFILE));
 
 
 
 
 
 
 
 
336 fossil_free(zDbName);
337 }
338 }else if( strncmp(zCmd, "status", nCmd)==0 ){
339 fossil_print("TBD...\n");
 
 
 
 
340 }else{
341 fossil_fatal("Unknown subcommand \"%s\"."
342 " Should be one of: clear init list status", zCmd);
343 }
344 }
345
346 /*
347 ** WEBPAGE: cachestat
@@ -380,12 +405,19 @@
380 sqlite3_finalize(pStmt);
381 @ </ol>
382 }
383 zDbName = cacheName();
384 bigSizeName(sizeof(zBuf), zBuf, file_size(zDbName, ExtFILE));
385 @ <p>cache-file name: %h(zDbName)</p>
386 @ <p>cache-file size: %s(zBuf)</p>
 
 
 
 
 
 
 
387 fossil_free(zDbName);
388 sqlite3_close(db);
389 }
390 style_finish_page();
391 }
392
--- src/cache.c
+++ src/cache.c
@@ -197,10 +197,17 @@
197 sqlite3_finalize(pStmt);
198 sqlite3_exec(db, rc ? "COMMIT" : "ROLLBACK", 0, 0, 0);
199 sqlite3_close(db);
200 }
201
202 /*
203 ** SETTING: max-cache-entry width=10 default=10
204 **
205 ** This is the maximum number of entries to allow in the web-cache
206 ** for tarballs, ZIP-archives, and SQL-archives.
207 */
208
209 /*
210 ** Attempt to read content out of the cache with the given zKey. Return
211 ** non-zero on success and zero if unable to locate the content.
212 **
213 ** Possible reasons for returning zero:
@@ -262,10 +269,12 @@
269 ** init Create the cache file if it does not already exist.
270 **
271 ** list|ls List the keys and content sizes and other stats for
272 ** all entries currently in the cache.
273 **
274 ** size ?N? Query or set the maximum number of entries in the cache.
275 **
276 ** status Show a summary of the cache status.
277 **
278 ** The cache is stored in a file that is distinct from the repository
279 ** but that is held in the same directory as the repository. The cache
280 ** file can be deleted in order to completely disable the cache.
@@ -303,12 +312,14 @@
312 sqlite3_close(db);
313 fossil_print("cache cleared\n");
314 }else{
315 fossil_print("nothing to clear; cache does not exist\n");
316 }
317 }else if( strncmp(zCmd, "list", nCmd)==0
318 || strncmp(zCmd, "ls", nCmd)==0
319 || strncmp(zCmd, "status", nCmd)==0
320 ){
321 db = cacheOpen(0);
322 if( db==0 ){
323 fossil_print("cache does not exist\n");
324 }else{
325 int nEntry = 0;
@@ -319,29 +330,43 @@
330 " FROM cache"
331 " ORDER BY tm DESC"
332 );
333 if( pStmt ){
334 while( sqlite3_step(pStmt)==SQLITE_ROW ){
335 if( zCmd[0]=='l' ){
336 fossil_print("%s %4d %8s %s\n",
337 sqlite3_column_text(pStmt, 3),
338 sqlite3_column_int(pStmt, 2),
339 sqlite3_column_text(pStmt, 1),
340 sqlite3_column_text(pStmt, 0));
341 }
342 nEntry++;
343 }
344 sqlite3_finalize(pStmt);
345 }
346 sqlite3_close(db);
347 fossil_print(
348 "Filename: %s\n"
349 "Entries: %d\n"
350 "max-cache-entry: %d\n"
351 "Cache-file Size: %,lld\n",
352 zDbName,
353 nEntry,
354 db_get_int("max-cache-entry",10),
355 file_size(zDbName, ExtFILE)
356 );
357 fossil_free(zDbName);
358 }
359 }else if( strncmp(zCmd, "size", nCmd)==0 ){
360 if( g.argc>=4 ){
361 int n = atoi(g.argv[3]);
362 if( n>=5 ) db_set_int("max-cache-entry",n,0);
363 }
364 fossil_print("max-cache-entry: %d\n", db_get_int("max-cache-entry",10));
365 }else{
366 fossil_fatal("Unknown subcommand \"%s\"."
367 " Should be one of: clear init list size status", zCmd);
368 }
369 }
370
371 /*
372 ** WEBPAGE: cachestat
@@ -380,12 +405,19 @@
405 sqlite3_finalize(pStmt);
406 @ </ol>
407 }
408 zDbName = cacheName();
409 bigSizeName(sizeof(zBuf), zBuf, file_size(zDbName, ExtFILE));
410 @ <p>
411 @ cache-file name: %h(zDbName)<br>
412 @ cache-file size: %s(zBuf)<br>
413 @ max-cache-entry: %d(db_get_int("max-cache-entry",10))
414 @ </p>
415 @ <p>
416 @ Use the "<a href="%R/help?cmd=cache">fossil cache</a>" command
417 @ on the command-line to create and configure the web-cache.
418 @ </p>
419 fossil_free(zDbName);
420 sqlite3_close(db);
421 }
422 style_finish_page();
423 }
424

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button