Fossil SCM
Improvements to the "fossil cache" command.
Commit
e0ebe6f0338825affb13e19d3f9c2af96c292ca73308a5d7dc38d7e9ec03cfbd
Parent
e0686dda41b9990…
1 file changed
+46
-14
+46
-14
| --- src/cache.c | ||
| +++ src/cache.c | ||
| @@ -197,10 +197,17 @@ | ||
| 197 | 197 | sqlite3_finalize(pStmt); |
| 198 | 198 | sqlite3_exec(db, rc ? "COMMIT" : "ROLLBACK", 0, 0, 0); |
| 199 | 199 | sqlite3_close(db); |
| 200 | 200 | } |
| 201 | 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 | + | |
| 202 | 209 | /* |
| 203 | 210 | ** Attempt to read content out of the cache with the given zKey. Return |
| 204 | 211 | ** non-zero on success and zero if unable to locate the content. |
| 205 | 212 | ** |
| 206 | 213 | ** Possible reasons for returning zero: |
| @@ -262,10 +269,12 @@ | ||
| 262 | 269 | ** init Create the cache file if it does not already exist. |
| 263 | 270 | ** |
| 264 | 271 | ** list|ls List the keys and content sizes and other stats for |
| 265 | 272 | ** all entries currently in the cache. |
| 266 | 273 | ** |
| 274 | +** size ?N? Query or set the maximum number of entries in the cache. | |
| 275 | +** | |
| 267 | 276 | ** status Show a summary of the cache status. |
| 268 | 277 | ** |
| 269 | 278 | ** The cache is stored in a file that is distinct from the repository |
| 270 | 279 | ** but that is held in the same directory as the repository. The cache |
| 271 | 280 | ** file can be deleted in order to completely disable the cache. |
| @@ -303,12 +312,14 @@ | ||
| 303 | 312 | sqlite3_close(db); |
| 304 | 313 | fossil_print("cache cleared\n"); |
| 305 | 314 | }else{ |
| 306 | 315 | fossil_print("nothing to clear; cache does not exist\n"); |
| 307 | 316 | } |
| 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 | + ){ | |
| 310 | 321 | db = cacheOpen(0); |
| 311 | 322 | if( db==0 ){ |
| 312 | 323 | fossil_print("cache does not exist\n"); |
| 313 | 324 | }else{ |
| 314 | 325 | int nEntry = 0; |
| @@ -319,29 +330,43 @@ | ||
| 319 | 330 | " FROM cache" |
| 320 | 331 | " ORDER BY tm DESC" |
| 321 | 332 | ); |
| 322 | 333 | if( pStmt ){ |
| 323 | 334 | 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 | + } | |
| 329 | 342 | nEntry++; |
| 330 | 343 | } |
| 331 | 344 | sqlite3_finalize(pStmt); |
| 332 | 345 | } |
| 333 | 346 | 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 | + ); | |
| 336 | 357 | fossil_free(zDbName); |
| 337 | 358 | } |
| 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)); | |
| 340 | 365 | }else{ |
| 341 | 366 | 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); | |
| 343 | 368 | } |
| 344 | 369 | } |
| 345 | 370 | |
| 346 | 371 | /* |
| 347 | 372 | ** WEBPAGE: cachestat |
| @@ -380,12 +405,19 @@ | ||
| 380 | 405 | sqlite3_finalize(pStmt); |
| 381 | 406 | @ </ol> |
| 382 | 407 | } |
| 383 | 408 | zDbName = cacheName(); |
| 384 | 409 | 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> | |
| 387 | 419 | fossil_free(zDbName); |
| 388 | 420 | sqlite3_close(db); |
| 389 | 421 | } |
| 390 | 422 | style_finish_page(); |
| 391 | 423 | } |
| 392 | 424 |
| --- 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 |