R/MediaCache-class.R

Defines functions purge MediaCache

Documented in MediaCache

### =========================================================================
### MediaCache objects
### -------------------------------------------------------------------------

### Just environments that only store Media objects

setClass("MediaCache", contains = "environment")

MediaCache <- function() {
  new("MediaCache", new.env(parent = emptyenv()))
}

setMethod("$<-", "MediaCache", function(x, name, value) {
  x[[name]] <- value
  x
})

setMethod("[[<-", "MediaCache", function(x, i, j, ..., value) {
  if (!missing(j))
    warning("argument 'j' is ignored")
  assign(i, value, x)
  x
})

setGeneric("assign",
           function (x, value, pos = -1, envir = as.environment(pos),
                     inherits = FALSE, immediate = TRUE)
           standardGeneric("assign"),
           signature = c("x", "value"))

setMethod("assign", "MediaCache",
          function (x, value, pos = -1, envir = as.environment(pos),
                    inherits = FALSE, immediate = TRUE)
          {
            if (!is(value, "Media"))
              stop("MediaCache only permits Media storage")
            callNextMethod()
          })

purge <- function(x) {
  rm(list=ls(x), envir=x)
  x
}

Try the restfulr package in your browser

Any scripts or data that you put into this service are public.

restfulr documentation built on June 16, 2022, 5:10 p.m.