{"id":13815349,"url":"https://github.com/alexk307/cache_deco","last_synced_at":"2025-04-12T17:51:31.986Z","repository":{"id":47775135,"uuid":"57451221","full_name":"alexk307/cache_deco","owner":"alexk307","description":"Backend agnostic cache decorator","archived":false,"fork":false,"pushed_at":"2022-12-26T20:22:38.000Z","size":47,"stargazers_count":81,"open_issues_count":4,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-09T00:01:43.230Z","etag":null,"topics":["cache","cache-control","cache-deco","redis"],"latest_commit_sha":null,"homepage":"","language":"Python","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/alexk307.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-30T16:21:12.000Z","updated_at":"2024-01-03T14:13:39.000Z","dependencies_parsed_at":"2023-01-31T01:15:23.640Z","dependency_job_id":null,"html_url":"https://github.com/alexk307/cache_deco","commit_stats":null,"previous_names":["alexk307/redis_cache"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexk307%2Fcache_deco","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexk307%2Fcache_deco/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexk307%2Fcache_deco/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexk307%2Fcache_deco/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexk307","download_url":"https://codeload.github.com/alexk307/cache_deco/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248610407,"owners_count":21132920,"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","cache-deco","redis"],"created_at":"2024-08-04T04:03:22.053Z","updated_at":"2025-04-12T17:51:31.960Z","avatar_url":"https://github.com/alexk307.png","language":"Python","readme":"# cache_deco [![Build Status](https://travis-ci.org/alexk307/redis_cache.svg?branch=master)](https://travis-ci.org/alexk307/cache_deco) [![Coverage Status](https://coveralls.io/repos/github/alexk307/redis_cache/badge.svg?branch=master)](https://coveralls.io/github/alexk307/redis_cache?branch=master)\n\nImplements high level function caching to any backend with a decorator\n\n# Install\n`pip install redis_cache_decorator`\n\n# Usage\n\n## Setup\n```python\nfrom cache_deco import Cache\nfrom backends.redis.redis_backend import RedisBackend\n# Create your cache backend\nredis = RedisBackend('localhost', 6379)\n# Use this backend as your cache\nc = Cache(redis)\n```\n\n## Cache\n\n```python\n@c.cache()\ndef my_method(a, b, c):\n  return a ** b ** c\n```\n\n### Options\n`expiration`: Number of seconds to keep the result in the cache. Defaults to 60 seconds when not specified.\n\ne.g.\n```python\n@c.cache(expiration=100)\ndef my_method():\n  ...\n```\n\n`signature_generator`: Callable function that generates the signature to cache on. The default signature generator will be used if not specified.\n\ne.g.\n\n```python\ndef sig_gen(*args, **kwargs):\n  return \"?\".join(args)\n  \n@c.cache(signature_generator=sig_gen)\ndef my_method():\n  ...\n```\n\n`invalidator`: Boolean to determine whether or not to return a cache invalidating function\n\ne.g.\n```python\n@c.cache(invalidator=True)\ndef my_method():\n    ...\n```\n\nNow when you call `my_method`, it will return two values. The first value is the cached return if a cache hit occurs, otherwise it's the return value from executing the function.\nThe second value is a callable function to invalidate the cache.\n\n```python\nreturn_value, invalidator = my_method()\n```\n\nTo invalidate the cached return, just call the invalidator:\n\n```python\ninvalidator()\n```\n# Custom Backends\nYou can use any backend for the cache by implementing the [base class](https://github.com/alexk307/cache_deco/blob/master/backends/backend_base.py)\n\n# Contributing\nCheck for any open issues, or open one yourself! All contributions are appreciated.\n\n# Tests\n`nosetests`\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexk307%2Fcache_deco","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexk307%2Fcache_deco","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexk307%2Fcache_deco/lists"}