@@ -8,7 +8,8 @@ context("Cache")
88assign(" id" , 0L , .id_cache )
99ascending_id <- function (){
1010 x <- get(" id" , .id_cache )
11- x <- as.character(as.integer(x ) + 1L )
11+ x <- pad_left(as.integer(x ) + 1L , width = 8 , pad = " 0" )
12+ assert(identical(nchar(x ), 8L ))
1213 assign(" id" , x , .id_cache )
1314 x
1415}
@@ -97,6 +98,30 @@ test_that("pruning works by number of files works", {
9798
9899
99100
101+ test_that(" pruning works by number of files sorts by key if timestamp are identical" , {
102+ td <- file.path(tempdir(), " cache-test" )
103+ on.exit(unlink(td , recursive = TRUE ))
104+
105+ cache <- Cache $ new(td , hashfun = function (x ) ascending_id())
106+ k1 <- cache $ push(iris )
107+ k2 <- cache $ push(letters )
108+ k3 <- cache $ push(cars )
109+ expect_identical(cache $ n , 3L )
110+
111+ Sys.setFileTime(cache $ files $ path , " 1999-01-01 00:00:00" )
112+
113+ expect_identical(cache $ files $ key [[1 ]], k1 )
114+ expect_identical(cache $ files $ key [[2 ]], k2 )
115+ expect_identical(cache $ files $ key [[3 ]], k3 )
116+
117+ cache $ prune(max_files = 2 )
118+ expect_identical(cache $ read(cache $ files $ key [[1 ]]), letters )
119+ expect_identical(cache $ read(cache $ files $ key [[2 ]]), cars )
120+ cache $ purge()
121+ })
122+
123+
124+
100125
101126test_that(" pruning by size works" , {
102127 td <- file.path(tempdir(), " cache-test" )
0 commit comments