Skip to content

Commit 4e46109

Browse files
committed
Temporarily cache the context dir
1 parent 3795c01 commit 4e46109

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎R/sass_cache.R‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#' @keywords internal
3030
#' @export
3131
sass_cache_get_dir <- function(dir, create = FALSE) {
32+
if (!is.null(.caches[[dir]])) {
33+
return(.caches[[dir]])
34+
}
35+
3236
if (create) {
3337
# Create dir if needed
3438
if (!dir.exists(dir)) {
@@ -152,6 +156,11 @@ sass_cache_get <- function() {
152156
#' @keywords internal
153157
#' @export
154158
sass_cache_context_dir <- function() {
159+
# Cache the context directory for 0.5sec
160+
if (!is.null(.context_dir$dir) && (as.numeric(Sys.time()) - .context_dir$accessed) > 0.5) {
161+
return(.context_dir$dir)
162+
}
163+
155164
tryCatch(
156165
{
157166
# The usual place we'll look. This may be superseded below.
@@ -193,9 +202,15 @@ sass_cache_context_dir <- function() {
193202
dir.create(cache_dir)
194203
}
195204
)
196-
normalizePath(cache_dir)
205+
206+
cache_dir <- normalizePath(cache_dir)
207+
.context_dir$dir <- cache_dir
208+
.context_dir$accessed <- as.numeric(Sys.time())
209+
cache_dir
197210
}
198211

212+
.context_dir <- new.env(parent = emptyenv())
213+
199214

200215
#' Returns a hash of the object, including sass_file mtimes
201216
#'

0 commit comments

Comments
 (0)