expiringdictx


Nameexpiringdictx JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/AzideCupric/expiringdictx
Summary提供一个带有过期时间的字典数据结构,适用于缓存和临时存储。
upload_time2024-08-07 13:38:49
maintainerNone
docs_urlNone
authorNone
requires_python<4,>=3.9
licenseMIT
keywords expire dict lru
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ExpiringDictx

<div align="center">

[![codecov](https://codecov.io/gh/AzideCupric/expiringdictx/graph/badge.svg?token=879N3D5BJK)](https://codecov.io/gh/AzideCupric/expiringdictx)
[![Build Status](https://img.shields.io/github/actions/workflow/status/AzideCupric/expiringdictx/test.yml?branch=main)](https://github.com/AzideCupric/expiringdictx/actions/workflows/test.yml)
[![PyPI version](https://badge.fury.io/py/expiringdictx.svg)](https://badge.fury.io/py/expiringdictx)
[![Python version](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License](https://img.shields.io/github/license/AzideCupric/expiringdictx)](https://github.com/AzideCupric/expiringdictx/blob/main/LICENSE)

</div>

---

## 简介 | Introduction

这是一个带有过期时间的字典数据结构,适用于缓存和临时存储。  
This is a dictionary data structure with an expiration time, suitable for caching and temporary storage.

## 安装 | Install

### 使用 pip 安装 | Install with pip

```bash
pip install expiringdictx
```

### 使用 poetry 安装 | Install with poetry

```bash
poetry add expiringdictx
```

### 使用 pdm 安装 | Install with pdm

```bash
pdm add expiringdictx
```

## 使用 | Usage

### ExpiringDict

```python
from datetime import timedelta
from expiringdictx import ExpiringDict

# 创建一个 ExpiringDict 实例 | Create an ExpiringDict instance
cache = ExpiringDict[str, str](capacity=100, default_age=60)

# 添加一个元素,过期时间为默认值 | Add an item with the default expiration time
cache["key0"] = "value0"
# 添加一个元素,过期时间为 30 秒 | Add an item with an expiration time of 30 seconds
cache["key1", 30] = "value1"
# 添加一个元素,过期时间为 2 分钟 | Add an item with an expiration time of 2 minutes
cache["key2", timedelta(minutes=2)] = "value2"
# 或者使用 set 方法 | Or use the set method
cache.set("key3", "value3", 60)

# 获取一个元素 | Get an item
value0 = cache["key0"]
value1 = cache.get('key1')
# 获取时附带过期时间 | Get with expiration time
value2, deadtime2 = cache.get_with_deadtime('key2')

# 获取并删除一个元素 | pop an item
value3 = cache.pop('key3')
value4 = cache.popitem(least_recently=True)

# 获取元素ttl(剩余存活时间) | Get the ttl(time to live) of an item
ttl = cache.ttl('key0')
# 获取元素ddl(过期时间) | Get the ddl(deadline) of an item
ddl = cache.ddl('key0')

# 按照给定keys创建一个新的ExpiringDict | Create a new ExpiringDict with the given keys
new_cache = cache.fromkeys(['key0', 'key1', 'key2'], "default_value", 60)
# 按照给定可映射对象创建一个新的ExpiringDict | Create a new ExpiringDict with the given mapping
new_cache = cache.frommapping({'key0': 'value0', 'key1': ('value1', 1), 'key2': ('value2', timedelta(hours=2))}, 60)
# 从另一个ExpiringDict创建一个新的ExpiringDict | Create a new ExpiringDict from another ExpiringDict
new_cache = cache.fromexpiringdict(cache, 60)
```

## 测试 | Tests

运行单元测试: | Run the unit tests:

```bash
pytest tests/
```

## 致谢 | Thanks

[`lru-dict`](https://github.com/amitdev/lru-dict): ExpiringDict 的内部存储实现  
[`expiringdict`](https://github.com/mailgun/expiringdict): 本项目的灵感来源,在此基础上添加类型注解和其他功能

## 许可 | License

MIT

---

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AzideCupric/expiringdictx",
    "name": "expiringdictx",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.9",
    "maintainer_email": null,
    "keywords": "expire, dict, lru",
    "author": null,
    "author_email": "AzideCupric <rukuy@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/49/f9/7b23c9da981e10d33b25180e6a73b89cceb41d58887486f5a4dd843d9f40/expiringdictx-1.1.0.tar.gz",
    "platform": null,
    "description": "# ExpiringDictx\n\n<div align=\"center\">\n\n[![codecov](https://codecov.io/gh/AzideCupric/expiringdictx/graph/badge.svg?token=879N3D5BJK)](https://codecov.io/gh/AzideCupric/expiringdictx)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/AzideCupric/expiringdictx/test.yml?branch=main)](https://github.com/AzideCupric/expiringdictx/actions/workflows/test.yml)\n[![PyPI version](https://badge.fury.io/py/expiringdictx.svg)](https://badge.fury.io/py/expiringdictx)\n[![Python version](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)\n[![License](https://img.shields.io/github/license/AzideCupric/expiringdictx)](https://github.com/AzideCupric/expiringdictx/blob/main/LICENSE)\n\n</div>\n\n---\n\n## \u7b80\u4ecb | Introduction\n\n\u8fd9\u662f\u4e00\u4e2a\u5e26\u6709\u8fc7\u671f\u65f6\u95f4\u7684\u5b57\u5178\u6570\u636e\u7ed3\u6784\uff0c\u9002\u7528\u4e8e\u7f13\u5b58\u548c\u4e34\u65f6\u5b58\u50a8\u3002  \nThis is a dictionary data structure with an expiration time, suitable for caching and temporary storage.\n\n## \u5b89\u88c5 | Install\n\n### \u4f7f\u7528 pip \u5b89\u88c5 | Install with pip\n\n```bash\npip install expiringdictx\n```\n\n### \u4f7f\u7528 poetry \u5b89\u88c5 | Install with poetry\n\n```bash\npoetry add expiringdictx\n```\n\n### \u4f7f\u7528 pdm \u5b89\u88c5 | Install with pdm\n\n```bash\npdm add expiringdictx\n```\n\n## \u4f7f\u7528 | Usage\n\n### ExpiringDict\n\n```python\nfrom datetime import timedelta\nfrom expiringdictx import ExpiringDict\n\n# \u521b\u5efa\u4e00\u4e2a ExpiringDict \u5b9e\u4f8b | Create an ExpiringDict instance\ncache = ExpiringDict[str, str](capacity=100, default_age=60)\n\n# \u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\uff0c\u8fc7\u671f\u65f6\u95f4\u4e3a\u9ed8\u8ba4\u503c | Add an item with the default expiration time\ncache[\"key0\"] = \"value0\"\n# \u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\uff0c\u8fc7\u671f\u65f6\u95f4\u4e3a 30 \u79d2 | Add an item with an expiration time of 30 seconds\ncache[\"key1\", 30] = \"value1\"\n# \u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\uff0c\u8fc7\u671f\u65f6\u95f4\u4e3a 2 \u5206\u949f | Add an item with an expiration time of 2 minutes\ncache[\"key2\", timedelta(minutes=2)] = \"value2\"\n# \u6216\u8005\u4f7f\u7528 set \u65b9\u6cd5 | Or use the set method\ncache.set(\"key3\", \"value3\", 60)\n\n# \u83b7\u53d6\u4e00\u4e2a\u5143\u7d20 | Get an item\nvalue0 = cache[\"key0\"]\nvalue1 = cache.get('key1')\n# \u83b7\u53d6\u65f6\u9644\u5e26\u8fc7\u671f\u65f6\u95f4 | Get with expiration time\nvalue2, deadtime2 = cache.get_with_deadtime('key2')\n\n# \u83b7\u53d6\u5e76\u5220\u9664\u4e00\u4e2a\u5143\u7d20 | pop an item\nvalue3 = cache.pop('key3')\nvalue4 = cache.popitem(least_recently=True)\n\n# \u83b7\u53d6\u5143\u7d20ttl(\u5269\u4f59\u5b58\u6d3b\u65f6\u95f4) | Get the ttl(time to live) of an item\nttl = cache.ttl('key0')\n# \u83b7\u53d6\u5143\u7d20ddl(\u8fc7\u671f\u65f6\u95f4) | Get the ddl(deadline) of an item\nddl = cache.ddl('key0')\n\n# \u6309\u7167\u7ed9\u5b9akeys\u521b\u5efa\u4e00\u4e2a\u65b0\u7684ExpiringDict | Create a new ExpiringDict with the given keys\nnew_cache = cache.fromkeys(['key0', 'key1', 'key2'], \"default_value\", 60)\n# \u6309\u7167\u7ed9\u5b9a\u53ef\u6620\u5c04\u5bf9\u8c61\u521b\u5efa\u4e00\u4e2a\u65b0\u7684ExpiringDict | Create a new ExpiringDict with the given mapping\nnew_cache = cache.frommapping({'key0': 'value0', 'key1': ('value1', 1), 'key2': ('value2', timedelta(hours=2))}, 60)\n# \u4ece\u53e6\u4e00\u4e2aExpiringDict\u521b\u5efa\u4e00\u4e2a\u65b0\u7684ExpiringDict | Create a new ExpiringDict from another ExpiringDict\nnew_cache = cache.fromexpiringdict(cache, 60)\n```\n\n## \u6d4b\u8bd5 | Tests\n\n\u8fd0\u884c\u5355\u5143\u6d4b\u8bd5\uff1a | Run the unit tests:\n\n```bash\npytest tests/\n```\n\n## \u81f4\u8c22 | Thanks\n\n[`lru-dict`](https://github.com/amitdev/lru-dict): ExpiringDict \u7684\u5185\u90e8\u5b58\u50a8\u5b9e\u73b0  \n[`expiringdict`](https://github.com/mailgun/expiringdict): \u672c\u9879\u76ee\u7684\u7075\u611f\u6765\u6e90\uff0c\u5728\u6b64\u57fa\u7840\u4e0a\u6dfb\u52a0\u7c7b\u578b\u6ce8\u89e3\u548c\u5176\u4ed6\u529f\u80fd\n\n## \u8bb8\u53ef | License\n\nMIT\n\n---\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\u63d0\u4f9b\u4e00\u4e2a\u5e26\u6709\u8fc7\u671f\u65f6\u95f4\u7684\u5b57\u5178\u6570\u636e\u7ed3\u6784\uff0c\u9002\u7528\u4e8e\u7f13\u5b58\u548c\u4e34\u65f6\u5b58\u50a8\u3002",
    "version": "1.1.0",
    "project_urls": {
        "Documentation": "https://github.com/AzideCupric/expiringdictx",
        "Homepage": "https://github.com/AzideCupric/expiringdictx",
        "Repository": "https://github.com/AzideCupric/expiringdictx"
    },
    "split_keywords": [
        "expire",
        " dict",
        " lru"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b7cdff116c050330c4b8c8ebc657f40501460c3e38905fb15993ef21f7d24208",
                "md5": "6ee5b6086332ce67710b1806c5243fed",
                "sha256": "f5d38ae23b46a8f97da27ce0dd74e669430d43b2efe98232a4a81f10b43cde25"
            },
            "downloads": -1,
            "filename": "expiringdictx-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6ee5b6086332ce67710b1806c5243fed",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.9",
            "size": 7596,
            "upload_time": "2024-08-07T13:38:48",
            "upload_time_iso_8601": "2024-08-07T13:38:48.458969Z",
            "url": "https://files.pythonhosted.org/packages/b7/cd/ff116c050330c4b8c8ebc657f40501460c3e38905fb15993ef21f7d24208/expiringdictx-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "49f97b23c9da981e10d33b25180e6a73b89cceb41d58887486f5a4dd843d9f40",
                "md5": "092070f612d48c4e0bbb03eb0edb7eb4",
                "sha256": "f590a4bd656a5317c51e696c2f48fee97e1d3feb6de87e00cebeaad9035824fa"
            },
            "downloads": -1,
            "filename": "expiringdictx-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "092070f612d48c4e0bbb03eb0edb7eb4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.9",
            "size": 9648,
            "upload_time": "2024-08-07T13:38:49",
            "upload_time_iso_8601": "2024-08-07T13:38:49.927543Z",
            "url": "https://files.pythonhosted.org/packages/49/f9/7b23c9da981e10d33b25180e6a73b89cceb41d58887486f5a4dd843d9f40/expiringdictx-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-07 13:38:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AzideCupric",
    "github_project": "expiringdictx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "expiringdictx"
}
        
Elapsed time: 0.30944s