{"id":15406776,"url":"https://github.com/dannyben/webcache","last_synced_at":"2025-04-18T02:51:29.819Z","repository":{"id":8681535,"uuid":"59353301","full_name":"DannyBen/webcache","owner":"DannyBen","description":"Hassle-free caching for HTTP download with ruby","archived":false,"fork":false,"pushed_at":"2024-01-09T05:44:32.000Z","size":80,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T19:40:06.573Z","etag":null,"topics":["cache","cache-control","gem","ruby","webcache"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DannyBen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2016-05-21T10:00:37.000Z","updated_at":"2025-03-30T19:27:52.000Z","dependencies_parsed_at":"2024-01-09T06:42:49.864Z","dependency_job_id":null,"html_url":"https://github.com/DannyBen/webcache","commit_stats":{"total_commits":89,"total_committers":2,"mean_commits":44.5,"dds":0.4382022471910112,"last_synced_commit":"532fb3e11510306d1170a3203c1d6e13406bf9c8"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fwebcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fwebcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fwebcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fwebcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DannyBen","download_url":"https://codeload.github.com/DannyBen/webcache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249416780,"owners_count":21268130,"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","cache-control","gem","ruby","webcache"],"created_at":"2024-10-01T16:25:19.719Z","updated_at":"2025-04-18T02:51:29.793Z","avatar_url":"https://github.com/DannyBen.png","language":"Ruby","readme":"# WebCache\n\n[![Gem Version](https://badge.fury.io/rb/webcache.svg)](https://badge.fury.io/rb/webcache)\n[![Build Status](https://github.com/DannyBen/webcache/workflows/Test/badge.svg)](https://github.com/DannyBen/webcache/actions?query=workflow%3ATest)\n[![Maintainability](https://api.codeclimate.com/v1/badges/022f555211d47d655988/maintainability)](https://codeclimate.com/github/DannyBen/webcache/maintainability)\n\n---\n\nHassle-free caching for HTTP download.\n\n---\n\n## Install\n\n```\n$ gem install webcache\n```\n\nOr with bundler:\n\n```ruby\ngem 'webcache'\n```\n\n## Usage\n\nWebCache can be used both as an instance, and as a static class.\n\n```ruby\nrequire 'webcache'\n\n# Instance\ncache = WebCache.new life: '3h'\nresponse = cache.get 'http://example.com'\n\n# Static\nWebCache.life = '3h'\nWebCache.get 'http://example.com'\n```\n\nThe design intention is to provide both a globally available singleton\n`WebCache` object, as well as multiple caching instances, with different\nsettings - depending on the use case.\n\nNote that the examples in this README are all using the instance syntax, but\nall methods are also available statically.\n\nThis is the basic usage pattern:\n\n```ruby\nrequire 'webcache'\ncache = WebCache.new\nresponse = cache.get 'http://example.com'\nputs response             # =\u003e \"\u003chtml\u003e...\u003c/html\u003e\"\nputs response.content     # =\u003e same as above\nputs response.to_s        # =\u003e same as above\nputs response.error       # =\u003e nil\nputs response.base_uri    # =\u003e \"http://example.com/\"\n```\n\nBy default, the cached objects are stored in the `./cache` directory, and\nexpire after 60 minutes. The cache directory will be created as needed, and\nthe permissions of the cached files can be specified if needed.\n\nYou can change these settings on initialization:\n\n```ruby\ncache = WebCache.new dir: 'tmp/my_cache', life: '3d', permissions: 0o640\nresponse = cache.get 'http://example.com'\n```\n\nOr later:\n\n```ruby\ncache = WebCache.new\ncache.dir = 'tmp/my_cache'\ncache.life = '4h'\ncache.permissions = 0o640\nresponse = cache.get 'http://example.com'\n```\n\nThe `life` property accepts any of these formats:\n\n```ruby\ncache.life = 10     # 10 seconds\ncache.life = '20s'  # 20 seconds\ncache.life = '10m'  # 10 minutes\ncache.life = '10h'  # 10 hours\ncache.life = '10d'  # 10 days\n```\n\nUse the `cached?` method to check if a URL is cached:\n\n```ruby\ncache = WebCache.new\ncache.cached? 'http://example.com'\n# =\u003e false\n\nresponse = cache.get 'http://example.com'\ncache.cached? 'http://example.com'\n# =\u003e true\n```\n\nUse `enable` and `disable` to toggle caching on and off:\n\n```ruby\ncache = WebCache.new\ncache.disable\ncache.enabled? \n# =\u003e false\n\nresponse = cache.get 'http://example.com'\ncache.cached? 'http://example.com'\n# =\u003e false\n\ncache.enable\nresponse = cache.get 'http://example.com'\ncache.cached? 'http://example.com'\n# =\u003e true\n```\n\nUse `clear url` to remove a cached object if it exists:\n\n```ruby\ncache = WebCache.new\nresponse = cache.get 'http://example.com'\ncache.cached? 'http://example.com'\n# =\u003e true\n\ncache.clear 'http://example.com'\ncache.cached? 'http://example.com'\n# =\u003e false\n```\n\nUse `flush` to delete the entire cache directory:\n\n```ruby\ncache = WebCache.new\ncache.flush\n```\n\nUse `force: true` to force download even if the object is cached:\n\n```ruby\ncache = WebCache.new\nresponse = cache.get 'http://example.com', force: true\n```\n\n## Authentication\n\nTo configure an authentication header, use the `auth` option. Similarly to\nthe other options, this can be set directly on the static class, on instance\ninitialization, or later on the instance:\n\n```ruby\ncache = WebCache.new auth: '...'\ncache.get 'http://example.com'      # authenticated\n\ncache = WebCache.new\ncache.auth = '...'\ncache.get 'http://example.com'      # authenticated\n\nWebCache.auth = '...'\nWebCache.get 'http://example.com'   # authenticated\n```\n\nFor basic authentication, provide a hash:\n\n```ruby\ncache = WebCache.new auth: { user: 'user', pass: 's3cr3t' }\n```\n\nFor other authentication headers, simply provide the header string:\n\n```ruby\ncache = WebCache.new auth: \"Bearer t0k3n\"\n```\n\n## Response Object\n\nThe response object holds these properties:\n\n### `response.content`\n\nContains the HTML content. In case of an error, this will include the\nerror message. The `#to_s` method of the response object also returns\nthe same content.\n\n### `response.error`\n\nIn case of an error, this contains the error message, `nil` otherwise.\n\n### `response.code`\n\nContains the HTTP code, or `nil` if there was a non-HTTP error.\n\n### `response.success?`\n\nA convenience method, returns true if `error` is empty.\n\n### `response.base_uri`\n\nContains the actual address of the page. This is useful when the request\nis redirected. For example, `http://example.com` will set the \n`base_uri` to `http://example.com/` (note the trailing slash).\n\n## Related Projects\n\nFor a similar gem that provides general purpose caching, see the \n[Lightly gem][lightly].\n\n## Contributing / Support\n\nIf you experience any issue, have a question or a suggestion, or if you wish\nto contribute, feel free to [open an issue][issues].\n\n---\n\n[lightly]: https://github.com/DannyBen/lightly\n[issues]: https://github.com/DannyBen/webcache/issues\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Fwebcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdannyben%2Fwebcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Fwebcache/lists"}