py-timed-cache


Namepy-timed-cache JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/NicoAdrian/timed-cache
SummaryPure Python timed-cache
upload_time2023-05-22 08:23:36
maintainer
docs_urlNone
authorNicolas Adrian
requires_python
licenseMIT
keywords cache timed-cache timedcache
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # timed-cache

Pure Python timed-cache that behaves like a regular `dict`.
Can also be used as a decorator to cache function calls (works for async functions as well).

## Installation

`pip install py-timed-cache`

## Example

```python
from timedcache import TimedCache

my_cache = TimedCache(1) # 1 second cache
my_cache["foo"] = "bar" # all dict methods works as if it was a normal dict
for k, v in my_cache.items():
    print(k, v) # will print foo bar

# Also works for functions

@TimedCache(5)
def foo(number):
    # some expensive compute...
    print("begin computation...")
    result = number * 10**30
    print("end computation")
    return res

big_number = foo(42) # cache MISS ==> this will print both statements above

big_number_again = foo(42) # Called with same argument(s) ==> cache HIT, returns immediately
```

## Python versions

Python >= 3.6 are supported

## Tests

This project uses `unittest`.

Run `python tests/test_timedcache.py`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/NicoAdrian/timed-cache",
    "name": "py-timed-cache",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "cache,timed-cache,timedcache",
    "author": "Nicolas Adrian",
    "author_email": "nicolasadrian3@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8f/87/e717964fe732bf0bc83396458d01d99654772b5ed722b6574486a3134efc/py-timed-cache-1.0.2.tar.gz",
    "platform": null,
    "description": "# timed-cache\n\nPure Python timed-cache that behaves like a regular `dict`.\nCan also be used as a decorator to cache function calls (works for async functions as well).\n\n## Installation\n\n`pip install py-timed-cache`\n\n## Example\n\n```python\nfrom timedcache import TimedCache\n\nmy_cache = TimedCache(1) # 1 second cache\nmy_cache[\"foo\"] = \"bar\" # all dict methods works as if it was a normal dict\nfor k, v in my_cache.items():\n    print(k, v) # will print foo bar\n\n# Also works for functions\n\n@TimedCache(5)\ndef foo(number):\n    # some expensive compute...\n    print(\"begin computation...\")\n    result = number * 10**30\n    print(\"end computation\")\n    return res\n\nbig_number = foo(42) # cache MISS ==> this will print both statements above\n\nbig_number_again = foo(42) # Called with same argument(s) ==> cache HIT, returns immediately\n```\n\n## Python versions\n\nPython >= 3.6 are supported\n\n## Tests\n\nThis project uses `unittest`.\n\nRun `python tests/test_timedcache.py`\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Pure Python timed-cache",
    "version": "1.0.2",
    "project_urls": {
        "Homepage": "https://github.com/NicoAdrian/timed-cache"
    },
    "split_keywords": [
        "cache",
        "timed-cache",
        "timedcache"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8f87e717964fe732bf0bc83396458d01d99654772b5ed722b6574486a3134efc",
                "md5": "d15d16012f65d12b14a7be05ccd1aef2",
                "sha256": "c30445220261a2fa2c049f51648b22af94b1273bde1e3f2f189c3e4012f2b89e"
            },
            "downloads": -1,
            "filename": "py-timed-cache-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d15d16012f65d12b14a7be05ccd1aef2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3717,
            "upload_time": "2023-05-22T08:23:36",
            "upload_time_iso_8601": "2023-05-22T08:23:36.161901Z",
            "url": "https://files.pythonhosted.org/packages/8f/87/e717964fe732bf0bc83396458d01d99654772b5ed722b6574486a3134efc/py-timed-cache-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-22 08:23:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NicoAdrian",
    "github_project": "timed-cache",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "py-timed-cache"
}
        
Elapsed time: 0.08240s