Skip to content

Commit

Permalink
Merge pull request #16 from abelcastilloavant/add_accessors
Browse files Browse the repository at this point in the history
add accessors to cache objects
  • Loading branch information
kirillseva authored Mar 5, 2018
2 parents 69fe784 + b3b5698 commit 903764e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: cacher
Type: Package
Title: cacher (http://github.com/kirillseva/cacher)
Description: In-memory cache interfaces for R.
Version: 0.1.2
Version: 0.1.3
Author: Kirill Sevastyanenko <kirillseva@gmail.com>
Maintainer: Kirill Sevastyanenko <kirillseva@gmail.com>
Authors@R: c(person("Kirill", "Sevastyanenko",
Expand All @@ -22,4 +22,4 @@ Suggests:
Roxygen: list(wrap = FALSE)
URL: http://github.com/kirillseva/cacher
BugReports: http://github.com/kirillseva/cacher/issues
RoxygenNote: 5.0.1.9000
RoxygenNote: 5.0.0
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method("[[",LRUcache_)
S3method("[[<-",LRUcache_)
S3method(LRUcache,character)
S3method(LRUcache,numeric)
export(LRUcache)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Version 0.1.3
- Allows reading and writing to a cache via `[[`.

# Version 0.1.2
- Added a method to give a list of keys for all objects in a cache.

Expand Down
5 changes: 5 additions & 0 deletions R/accessors.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#' @export
`[[.LRUcache_` <- function(cache, key) { cache$get(key) }

#' @export
`[[<-.LRUcache_` <- function(cache, key, value) { cache$set(key, value = value) }
11 changes: 11 additions & 0 deletions tests/testthat/test-accessors.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test_that("`[[` allows retrieval of objects from cache", {
x <- LRUcache(1)
x$set("a", 10)
expect_equal(x[["a"]], 10)
})

test_that("`[[` allows assignment of objects to cache", {
y <- LRUcache(1)
y[["b"]] <- 20
expect_equal(y$get("b"), 20)
})

0 comments on commit 903764e

Please sign in to comment.