File: CacheInfo-class.R

package info (click to toggle)
r-cran-restfulr 0.0.15-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 200 kB
  • sloc: ansic: 67; sh: 13; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 1,029 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
### =========================================================================
### CacheInfo class
### -------------------------------------------------------------------------

setClass("CacheInfo",
         representation(expires = "POSIXt",
                        lastModified = "POSIXt",
                        hash = "character_OR_NULL"))

CacheInfo <- function(expires = Sys.time(),
                      lastModified = as.POSIXct("1960-01-01"),
                      hash = NULL)
{
  if (!is.null(hash) && !isSingleString(hash))
    stop("If not NULL, 'hash' must be a single, non-NA string")
  new("CacheInfo", expires = expires, lastModified = lastModified, hash = hash)
}

setGeneric("expired", function(x, ...) standardGeneric("expired"))

setMethod("expired", "CacheInfo", function(x) {
  x@expires < Sys.time()
})

setGeneric("modifiedSince",
           function(x, date, ...) standardGeneric("modifiedSince"))
  
setMethod("modifiedSince", c("CacheInfo", "Date"), function(x, date) {
  x@lastModified >= date
})