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.

drh 2018-04-10 11:55 trunk
Commit 7ffa5ae027bf03d7643601ef23271b63baba6d4b748457ac04070a20979d7f7e
1 file changed +13 -4
+13 -4
--- src/cache.c
+++ src/cache.c
@@ -165,17 +165,25 @@
165165
sqlite3_bind_int(pStmt, 3, sqlite3_last_insert_rowid(db));
166166
if( sqlite3_step(pStmt)!=SQLITE_DONE) goto cache_write_end;
167167
rc = sqlite3_changes(db);
168168
169169
/* 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
+ */
171178
if( rc ){
172179
nKeep = db_get_int("max-cache-entry",10);
173180
sqlite3_finalize(pStmt);
174181
pStmt = cacheStmt(db,
175182
"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"
177185
" LIMIT -1 OFFSET ?1)");
178186
if( pStmt ){
179187
sqlite3_bind_int(pStmt, 1, nKeep);
180188
sqlite3_step(pStmt);
181189
}
@@ -291,11 +299,12 @@
291299
sqlite3_close(db);
292300
fossil_print("cache cleared\n");
293301
}else{
294302
fossil_print("nothing to clear; cache does not exist\n");
295303
}
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 )){
297306
db = cacheOpen(0);
298307
if( db==0 ){
299308
fossil_print("cache does not exist\n");
300309
}else{
301310
int nEntry = 0;
@@ -350,11 +359,11 @@
350359
char *zDbName = cacheName();
351360
cache_register_sizename(db);
352361
pStmt = cacheStmt(db,
353362
"SELECT key, sizename(sz), nRef, datetime(tm,'unixepoch')"
354363
" FROM cache"
355
- " ORDER BY tm DESC"
364
+ " ORDER BY (tm + 3600*min(nRef,48)) DESC"
356365
);
357366
if( pStmt ){
358367
@ <ol>
359368
while( sqlite3_step(pStmt)==SQLITE_ROW ){
360369
const unsigned char *zName = sqlite3_column_text(pStmt,0);
361370
--- 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

Keyboard Shortcuts

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