smoothcache


Namesmoothcache JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummarySimple, in-memory, thread-safe caching system for python programs.
upload_time2023-07-10 05:37:31
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords cache
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # smoothcache

`smoothcache` is a simple, in-memory, thread-safe caching system for your python programs.

## Installation

```
pip install smoothcache
```

## Usage
On import, the library creates a global cache object named `Cache` that you can interact with.

``` python

from smoothcache import Cache

Cache.set("cache key", "cache value")

```

### Interacting with the cache object

The cache object exposes 4 methods for interacting with the cache:

 - set
 - get
 - clear
 - remove

#### Set

``` python
Cache.set(key, value, ttl=None)
```

The `set` method adds an entry to the cache.

The `key` parameter is how you can access the cached value.

The `ttl` parameter is the Time-to-Live value (in seconds) that the cache entry will remain valid.

After `ttl` seconds has passed, the cache will no longer return the value. The default ttl value is set at 3600 seconds (1 hour) and can be modified in the cache settings.

If a key is passed to `set` that already exists, the entry gets overridden. This behavior can be changed in the cache settings to instead raise a `KeyAlreadyExistsError` when a duplicate key is passed.

#### Get

``` python
Cache.get(key, default=None)
```

The `get` method retrieves an entry from the cache.

The `key` parameter is the value of the entries key set with the `set` method.

The `default` parameter is the value that will be returned if the entry is no longer valid, or doesn't exist.

`get` can also be configured in the cache settings to raise an `EntryNotFoundError` when the specified key doesn't exist or an `EntryExpiredError` when the specified cache entry has expired.

`get` returns a `CacheResult` object with two attributes (`key` and `value`) when the entry is found. Otherwise, `get` returns `default`.

#### Clear

``` python
Cache.clear()
```

The `clear` method removes all entries from the cache

#### Remove

``` python
Cache.remove(key)
```

The `remove` method removes the specified key from the cache.

By default, if the key doesn't exist in the cache, the function silently returns and doesn't fail. This behavior can be changed in the cache settings to instead raise an `EntryNotFoundError`.

### Cache Settings

The `Cache` object's behavior can be modified with it's settings. Settings are accessed within the object's `settings` property.

``` python
# Cache.settings.<setting name> = <setting value>
# For example:
Cache.settings.error_on_dup_key = False
```

`error_on_dup_key`:

__Default:__ False

If true, raise a `KeyAlreadyExistsError` when `set` is called with a `key` that is already set in the cache. If false, the cache entry with `key` is overwritten if the key is already set.

`error_on_invalid_key`:

__Default:__ False

If true, raise an `EntryNotFoundError` when `get` or `remove` is called with a `key` that is not set in the cache. If false, the `get` call will return it's default and the `remove` call silently returns.

`error_on_expired_entry`:

__Default:__ False

If true, raise an `EntryExpiredError` when the entry returned from a `get` call has gone past it's TTL. If false, the `get` call will return it's default.

`default_ttl`:

__Default:__ 3600 (1 hour)

The TTL value (in seconds) set on any entry that does not explicitly have a TTL value.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "smoothcache",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "cache",
    "author": "",
    "author_email": "Mason Weaver <mason@swingproxy.com>",
    "download_url": "https://files.pythonhosted.org/packages/d5/2a/0e687d082b048c1164e2fc3067cea8260110a06bff1a998f7615191d5b61/smoothcache-1.0.0.tar.gz",
    "platform": null,
    "description": "# smoothcache\n\n`smoothcache` is a simple, in-memory, thread-safe caching system for your python programs.\n\n## Installation\n\n```\npip install smoothcache\n```\n\n## Usage\nOn import, the library creates a global cache object named `Cache` that you can interact with.\n\n``` python\n\nfrom smoothcache import Cache\n\nCache.set(\"cache key\", \"cache value\")\n\n```\n\n### Interacting with the cache object\n\nThe cache object exposes 4 methods for interacting with the cache:\n\n - set\n - get\n - clear\n - remove\n\n#### Set\n\n``` python\nCache.set(key, value, ttl=None)\n```\n\nThe `set` method adds an entry to the cache.\n\nThe `key` parameter is how you can access the cached value.\n\nThe `ttl` parameter is the Time-to-Live value (in seconds) that the cache entry will remain valid.\n\nAfter `ttl` seconds has passed, the cache will no longer return the value. The default ttl value is set at 3600 seconds (1 hour) and can be modified in the cache settings.\n\nIf a key is passed to `set` that already exists, the entry gets overridden. This behavior can be changed in the cache settings to instead raise a `KeyAlreadyExistsError` when a duplicate key is passed.\n\n#### Get\n\n``` python\nCache.get(key, default=None)\n```\n\nThe `get` method retrieves an entry from the cache.\n\nThe `key` parameter is the value of the entries key set with the `set` method.\n\nThe `default` parameter is the value that will be returned if the entry is no longer valid, or doesn't exist.\n\n`get` can also be configured in the cache settings to raise an `EntryNotFoundError` when the specified key doesn't exist or an `EntryExpiredError` when the specified cache entry has expired.\n\n`get` returns a `CacheResult` object with two attributes (`key` and `value`) when the entry is found. Otherwise, `get` returns `default`.\n\n#### Clear\n\n``` python\nCache.clear()\n```\n\nThe `clear` method removes all entries from the cache\n\n#### Remove\n\n``` python\nCache.remove(key)\n```\n\nThe `remove` method removes the specified key from the cache.\n\nBy default, if the key doesn't exist in the cache, the function silently returns and doesn't fail. This behavior can be changed in the cache settings to instead raise an `EntryNotFoundError`.\n\n### Cache Settings\n\nThe `Cache` object's behavior can be modified with it's settings. Settings are accessed within the object's `settings` property.\n\n``` python\n# Cache.settings.<setting name> = <setting value>\n# For example:\nCache.settings.error_on_dup_key = False\n```\n\n`error_on_dup_key`:\n\n__Default:__ False\n\nIf true, raise a `KeyAlreadyExistsError` when `set` is called with a `key` that is already set in the cache. If false, the cache entry with `key` is overwritten if the key is already set.\n\n`error_on_invalid_key`:\n\n__Default:__ False\n\nIf true, raise an `EntryNotFoundError` when `get` or `remove` is called with a `key` that is not set in the cache. If false, the `get` call will return it's default and the `remove` call silently returns.\n\n`error_on_expired_entry`:\n\n__Default:__ False\n\nIf true, raise an `EntryExpiredError` when the entry returned from a `get` call has gone past it's TTL. If false, the `get` call will return it's default.\n\n`default_ttl`:\n\n__Default:__ 3600 (1 hour)\n\nThe TTL value (in seconds) set on any entry that does not explicitly have a TTL value.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Simple, in-memory, thread-safe caching system for python programs.",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/Otach/smoothcache"
    },
    "split_keywords": [
        "cache"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8c8d89eea08e610b5fa9c716f725852cb2ccf6786c6a501ad68fb07cce59d3ec",
                "md5": "8f423782bf75b923b3f9ada242ba1cce",
                "sha256": "783e3a33a82b2d27f58489e4f8e1cd9f9ed6d9729da8de9ddac524b3178f6c11"
            },
            "downloads": -1,
            "filename": "smoothcache-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8f423782bf75b923b3f9ada242ba1cce",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5849,
            "upload_time": "2023-07-10T05:37:30",
            "upload_time_iso_8601": "2023-07-10T05:37:30.071742Z",
            "url": "https://files.pythonhosted.org/packages/8c/8d/89eea08e610b5fa9c716f725852cb2ccf6786c6a501ad68fb07cce59d3ec/smoothcache-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d52a0e687d082b048c1164e2fc3067cea8260110a06bff1a998f7615191d5b61",
                "md5": "1306ec639cae292efd6a2bb7f37872e2",
                "sha256": "bf42d7c8a9e0683bba4e8ce4ce747145d18bc294dbf3ff0b4d1081b3e713978e"
            },
            "downloads": -1,
            "filename": "smoothcache-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1306ec639cae292efd6a2bb7f37872e2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 5818,
            "upload_time": "2023-07-10T05:37:31",
            "upload_time_iso_8601": "2023-07-10T05:37:31.915023Z",
            "url": "https://files.pythonhosted.org/packages/d5/2a/0e687d082b048c1164e2fc3067cea8260110a06bff1a998f7615191d5b61/smoothcache-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-10 05:37:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Otach",
    "github_project": "smoothcache",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "smoothcache"
}
        
Elapsed time: 0.33075s