{"id":18247079,"url":"https://github.com/badbye/rcache","last_synced_at":"2025-04-08T19:35:29.697Z","repository":{"id":66175979,"uuid":"146871903","full_name":"badbye/rcache","owner":"badbye","description":"Cache data in a range of time in R language","archived":false,"fork":false,"pushed_at":"2019-06-19T04:00:25.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-14T15:17:23.224Z","etag":null,"topics":["cache","r"],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/badbye.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-31T09:37:05.000Z","updated_at":"2019-06-21T06:08:57.000Z","dependencies_parsed_at":"2023-02-20T23:16:09.616Z","dependency_job_id":null,"html_url":"https://github.com/badbye/rcache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badbye%2Frcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badbye%2Frcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badbye%2Frcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badbye%2Frcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/badbye","download_url":"https://codeload.github.com/badbye/rcache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247913014,"owners_count":21017081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","r"],"created_at":"2024-11-05T09:29:00.451Z","updated_at":"2025-04-08T19:35:29.665Z","avatar_url":"https://github.com/badbye.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"rcache\n======\n\nThis package offers a `Cacher` object, which can be used to cache data in a range of time.\n\n## Insallation\n\n```R\ndevtools::install_github('badbye/rcache')\n```\n\n## Usage\n\n```R\ncache = Cacher$new(expire = 3) # cache 3 seconds\ncache$set('a', 1)\ncache$get('a') # 1\nSys.sleep(3)\ncache$get('a') # NULL\n\n# set expire time explicitly\ncache$set('b', 1, expire=10)\n\n# exist or not\ncache$exist('b')  # return FALSE if it is expired\n\n# `get_callback` if key exists, return the cached value, otherwise\n# run the callback function and cache its returned value\ncache$get_callback('b', function() 123, expire=60)\nSys.sleep(10)\ncache$get_callback('b', function() 123, expire=60)\n```\n\nThe `get_callback` method sometimes could be very useful. Here is a satuation: \n\n```R\nold_data_fun \u003c- function() {\n Sys.Date() # the returned data will change every day\n}\ncache = Cacher$new() \nnew_data_fun \u003c- function() {\n  key = 'what ever you set'\n  time2tomorrow \u003c- function() {\n    tomorrow = as.numeric(as.POSIXct(format(Sys.Date() + 1, '%Y-%m-%d 00:00:00'))) \n    tomorrow - as.numeric(Sys.time())\n  } \n  cache$get_callback(key, old_data_fun, expire=time2tomorrow()) \n}\n```\n\nThe `new_data_fun` function will return data immediately if it is cached. Otherwise, it will call the `old_data_fun` function to get data, and cache it until tomorrow.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadbye%2Frcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadbye%2Frcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadbye%2Frcache/lists"}