Fossil SCM
Enhance the replacement algorithm for the tarball cache so that it gives extra weight to tarballs that have been accessed more than once.
Commit
7ffa5ae027bf03d7643601ef23271b63baba6d4b748457ac04070a20979d7f7e
Parent
3e94c7ed74a0774…
1 file changed
+13
-4
+13
-4
| --- src/cache.c | ||
| +++ src/cache.c | ||
| @@ -165,17 +165,25 @@ | ||
| 165 | 165 | sqlite3_bind_int(pStmt, 3, sqlite3_last_insert_rowid(db)); |
| 166 | 166 | if( sqlite3_step(pStmt)!=SQLITE_DONE) goto cache_write_end; |
| 167 | 167 | rc = sqlite3_changes(db); |
| 168 | 168 | |
| 169 | 169 | /* If the write was successful, truncate the cache to keep at most |
| 170 | - ** max-cache-entry entries in the cache */ | |
| 170 | + ** max-cache-entry entries in the cache. | |
| 171 | + ** | |
| 172 | + ** The cache entry replacement algorithm is approximately LRU | |
| 173 | + ** (least recently used). However, each access of an entry buys | |
| 174 | + ** that entry an extra hour of grace, so that more commonly accessed | |
| 175 | + ** entries are held in cache longer. The extra "grace" allotted to | |
| 176 | + ** an entry is limited to 2 days worth. | |
| 177 | + */ | |
| 171 | 178 | if( rc ){ |
| 172 | 179 | nKeep = db_get_int("max-cache-entry",10); |
| 173 | 180 | sqlite3_finalize(pStmt); |
| 174 | 181 | pStmt = cacheStmt(db, |
| 175 | 182 | "DELETE FROM cache WHERE rowid IN (" |
| 176 | - "SELECT rowid FROM cache ORDER BY tm DESC" | |
| 183 | + "SELECT rowid FROM cache" | |
| 184 | + " ORDER BY (tm + 3600*min(nRef,48)) DESC" | |
| 177 | 185 | " LIMIT -1 OFFSET ?1)"); |
| 178 | 186 | if( pStmt ){ |
| 179 | 187 | sqlite3_bind_int(pStmt, 1, nKeep); |
| 180 | 188 | sqlite3_step(pStmt); |
| 181 | 189 | } |
| @@ -291,11 +299,12 @@ | ||
| 291 | 299 | sqlite3_close(db); |
| 292 | 300 | fossil_print("cache cleared\n"); |
| 293 | 301 | }else{ |
| 294 | 302 | fossil_print("nothing to clear; cache does not exist\n"); |
| 295 | 303 | } |
| 296 | - }else if(( strncmp(zCmd, "list", nCmd)==0 ) || ( strncmp(zCmd, "ls", nCmd)==0 )){ | |
| 304 | + }else if(( strncmp(zCmd, "list", nCmd)==0 ) | |
| 305 | + || ( strncmp(zCmd, "ls", nCmd)==0 )){ | |
| 297 | 306 | db = cacheOpen(0); |
| 298 | 307 | if( db==0 ){ |
| 299 | 308 | fossil_print("cache does not exist\n"); |
| 300 | 309 | }else{ |
| 301 | 310 | int nEntry = 0; |
| @@ -350,11 +359,11 @@ | ||
| 350 | 359 | char *zDbName = cacheName(); |
| 351 | 360 | cache_register_sizename(db); |
| 352 | 361 | pStmt = cacheStmt(db, |
| 353 | 362 | "SELECT key, sizename(sz), nRef, datetime(tm,'unixepoch')" |
| 354 | 363 | " FROM cache" |
| 355 | - " ORDER BY tm DESC" | |
| 364 | + " ORDER BY (tm + 3600*min(nRef,48)) DESC" | |
| 356 | 365 | ); |
| 357 | 366 | if( pStmt ){ |
| 358 | 367 | @ <ol> |
| 359 | 368 | while( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 360 | 369 | const unsigned char *zName = sqlite3_column_text(pStmt,0); |
| 361 | 370 |
| --- src/cache.c | |
| +++ src/cache.c | |
| @@ -165,17 +165,25 @@ | |
| 165 | sqlite3_bind_int(pStmt, 3, sqlite3_last_insert_rowid(db)); |
| 166 | if( sqlite3_step(pStmt)!=SQLITE_DONE) goto cache_write_end; |
| 167 | rc = sqlite3_changes(db); |
| 168 | |
| 169 | /* If the write was successful, truncate the cache to keep at most |
| 170 | ** max-cache-entry entries in the cache */ |
| 171 | if( rc ){ |
| 172 | nKeep = db_get_int("max-cache-entry",10); |
| 173 | sqlite3_finalize(pStmt); |
| 174 | pStmt = cacheStmt(db, |
| 175 | "DELETE FROM cache WHERE rowid IN (" |
| 176 | "SELECT rowid FROM cache ORDER BY tm DESC" |
| 177 | " LIMIT -1 OFFSET ?1)"); |
| 178 | if( pStmt ){ |
| 179 | sqlite3_bind_int(pStmt, 1, nKeep); |
| 180 | sqlite3_step(pStmt); |
| 181 | } |
| @@ -291,11 +299,12 @@ | |
| 291 | sqlite3_close(db); |
| 292 | fossil_print("cache cleared\n"); |
| 293 | }else{ |
| 294 | fossil_print("nothing to clear; cache does not exist\n"); |
| 295 | } |
| 296 | }else if(( strncmp(zCmd, "list", nCmd)==0 ) || ( strncmp(zCmd, "ls", nCmd)==0 )){ |
| 297 | db = cacheOpen(0); |
| 298 | if( db==0 ){ |
| 299 | fossil_print("cache does not exist\n"); |
| 300 | }else{ |
| 301 | int nEntry = 0; |
| @@ -350,11 +359,11 @@ | |
| 350 | char *zDbName = cacheName(); |
| 351 | cache_register_sizename(db); |
| 352 | pStmt = cacheStmt(db, |
| 353 | "SELECT key, sizename(sz), nRef, datetime(tm,'unixepoch')" |
| 354 | " FROM cache" |
| 355 | " ORDER BY tm DESC" |
| 356 | ); |
| 357 | if( pStmt ){ |
| 358 | @ <ol> |
| 359 | while( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 360 | const unsigned char *zName = sqlite3_column_text(pStmt,0); |
| 361 |
| --- src/cache.c | |
| +++ src/cache.c | |
| @@ -165,17 +165,25 @@ | |
| 165 | sqlite3_bind_int(pStmt, 3, sqlite3_last_insert_rowid(db)); |
| 166 | if( sqlite3_step(pStmt)!=SQLITE_DONE) goto cache_write_end; |
| 167 | rc = sqlite3_changes(db); |
| 168 | |
| 169 | /* If the write was successful, truncate the cache to keep at most |
| 170 | ** max-cache-entry entries in the cache. |
| 171 | ** |
| 172 | ** The cache entry replacement algorithm is approximately LRU |
| 173 | ** (least recently used). However, each access of an entry buys |
| 174 | ** that entry an extra hour of grace, so that more commonly accessed |
| 175 | ** entries are held in cache longer. The extra "grace" allotted to |
| 176 | ** an entry is limited to 2 days worth. |
| 177 | */ |
| 178 | if( rc ){ |
| 179 | nKeep = db_get_int("max-cache-entry",10); |
| 180 | sqlite3_finalize(pStmt); |
| 181 | pStmt = cacheStmt(db, |
| 182 | "DELETE FROM cache WHERE rowid IN (" |
| 183 | "SELECT rowid FROM cache" |
| 184 | " ORDER BY (tm + 3600*min(nRef,48)) DESC" |
| 185 | " LIMIT -1 OFFSET ?1)"); |
| 186 | if( pStmt ){ |
| 187 | sqlite3_bind_int(pStmt, 1, nKeep); |
| 188 | sqlite3_step(pStmt); |
| 189 | } |
| @@ -291,11 +299,12 @@ | |
| 299 | sqlite3_close(db); |
| 300 | fossil_print("cache cleared\n"); |
| 301 | }else{ |
| 302 | fossil_print("nothing to clear; cache does not exist\n"); |
| 303 | } |
| 304 | }else if(( strncmp(zCmd, "list", nCmd)==0 ) |
| 305 | || ( strncmp(zCmd, "ls", nCmd)==0 )){ |
| 306 | db = cacheOpen(0); |
| 307 | if( db==0 ){ |
| 308 | fossil_print("cache does not exist\n"); |
| 309 | }else{ |
| 310 | int nEntry = 0; |
| @@ -350,11 +359,11 @@ | |
| 359 | char *zDbName = cacheName(); |
| 360 | cache_register_sizename(db); |
| 361 | pStmt = cacheStmt(db, |
| 362 | "SELECT key, sizename(sz), nRef, datetime(tm,'unixepoch')" |
| 363 | " FROM cache" |
| 364 | " ORDER BY (tm + 3600*min(nRef,48)) DESC" |
| 365 | ); |
| 366 | if( pStmt ){ |
| 367 | @ <ol> |
| 368 | while( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 369 | const unsigned char *zName = sqlite3_column_text(pStmt,0); |
| 370 |