mo-cache


Namemo-cache JSON
Version 0.0.8 PyPI version JSON
download
home_pagehttps://github.com/mouday/mo-cache
Summarya simple cache lib support memory、file、redis
upload_time2021-03-01 03:00:14
maintainer
docs_urlNone
authorPeng Shiyu
requires_python
licenseMIT
keywords cache
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Mo-Cache

![PyPI](https://img.shields.io/pypi/v/mo-cache.svg)
![PyPI - Downloads](https://img.shields.io/pypi/dm/mo-cache)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mo-cache)
![PyPI - License](https://img.shields.io/pypi/l/mo-cache)


a simple cache lib support memory、file、redis

Github: https://github.com/mouday/mo-cache

## install

```bash
pip install mo-cache
```

## demo

快速开始

```python
from mo_cache import MemoryCache

cache = MemoryCache()


# 此时的key默认是函数名 foo
@cache
def foo(a, b):
    return a + b

if __name__ == '__main__':
    foo()

```

## 更多示例

1、使用装饰器

```python

# 主动设置key, 过期时间单位:秒s
@cache(key='custom_key', expire=30)
def foo(a, b):
    return a + b
```

2、主动设置和获取

```python

cache.set(key='custom_key', value='value', expire=30)

value = cache.get(key='custom_key')
```

MemoryCache, FileCache, RedisCache实现了共同的接口(set/get/call),

只是构造参数稍有不同

```python

from mo_cache import MemoryCache, FileCache, RedisCache

memory_cache = MemoryCache()

file_cache = FileCache(cache_dir='cache')

redis_cache = RedisCache(redis_url='redis://localhost:6379/0')
```

## 继承体系

```python

class CacheAbstract(object):
    """统一的接口"""
    def set(self, key, value, expire=-1):
        pass

    def get(self, key):
        pass

class CacheDecorator(CacheAbstract):
    """cache 装饰器"""
    def __call__(self, key=None, expire=-1):
        pass

class MemoryCache(CacheDecorator):
    """内存缓存"""

class FileCache(CacheDecorator):
    """文件缓存"""

class RedisCache(CacheDecorator):
    """Redis 缓存"""

```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mouday/mo-cache",
    "name": "mo-cache",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "cache",
    "author": "Peng Shiyu",
    "author_email": "pengshiyuyx@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b7/20/f9a90499a89827cf892f47e175d57494ed83987ab3c5d242b473d85eeffc/mo-cache-0.0.8.tar.gz",
    "platform": "",
    "description": "# Mo-Cache\n\n![PyPI](https://img.shields.io/pypi/v/mo-cache.svg)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/mo-cache)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mo-cache)\n![PyPI - License](https://img.shields.io/pypi/l/mo-cache)\n\n\na simple cache lib support memory\u3001file\u3001redis\n\nGithub: https://github.com/mouday/mo-cache\n\n## install\n\n```bash\npip install mo-cache\n```\n\n## demo\n\n\u5feb\u901f\u5f00\u59cb\n\n```python\nfrom mo_cache import MemoryCache\n\ncache = MemoryCache()\n\n\n# \u6b64\u65f6\u7684key\u9ed8\u8ba4\u662f\u51fd\u6570\u540d foo\n@cache\ndef foo(a, b):\n    return a + b\n\nif __name__ == '__main__':\n    foo()\n\n```\n\n## \u66f4\u591a\u793a\u4f8b\n\n1\u3001\u4f7f\u7528\u88c5\u9970\u5668\n\n```python\n\n# \u4e3b\u52a8\u8bbe\u7f6ekey, \u8fc7\u671f\u65f6\u95f4\u5355\u4f4d\uff1a\u79d2s\n@cache(key='custom_key', expire=30)\ndef foo(a, b):\n    return a + b\n```\n\n2\u3001\u4e3b\u52a8\u8bbe\u7f6e\u548c\u83b7\u53d6\n\n```python\n\ncache.set(key='custom_key', value='value', expire=30)\n\nvalue = cache.get(key='custom_key')\n```\n\nMemoryCache, FileCache, RedisCache\u5b9e\u73b0\u4e86\u5171\u540c\u7684\u63a5\u53e3(set/get/call)\uff0c\n\n\u53ea\u662f\u6784\u9020\u53c2\u6570\u7a0d\u6709\u4e0d\u540c\n\n```python\n\nfrom mo_cache import MemoryCache, FileCache, RedisCache\n\nmemory_cache = MemoryCache()\n\nfile_cache = FileCache(cache_dir='cache')\n\nredis_cache = RedisCache(redis_url='redis://localhost:6379/0')\n```\n\n## \u7ee7\u627f\u4f53\u7cfb\n\n```python\n\nclass CacheAbstract(object):\n    \"\"\"\u7edf\u4e00\u7684\u63a5\u53e3\"\"\"\n    def set(self, key, value, expire=-1):\n        pass\n\n    def get(self, key):\n        pass\n\nclass CacheDecorator(CacheAbstract):\n    \"\"\"cache \u88c5\u9970\u5668\"\"\"\n    def __call__(self, key=None, expire=-1):\n        pass\n\nclass MemoryCache(CacheDecorator):\n    \"\"\"\u5185\u5b58\u7f13\u5b58\"\"\"\n\nclass FileCache(CacheDecorator):\n    \"\"\"\u6587\u4ef6\u7f13\u5b58\"\"\"\n\nclass RedisCache(CacheDecorator):\n    \"\"\"Redis \u7f13\u5b58\"\"\"\n\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "a simple cache lib support memory\u3001file\u3001redis",
    "version": "0.0.8",
    "project_urls": {
        "Homepage": "https://github.com/mouday/mo-cache"
    },
    "split_keywords": [
        "cache"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c3f126689a304c84b631464790d5a87a0da69e4eecfc3c657fb8e5b1ba66aa9a",
                "md5": "03da5e36284a3a9b4ca9c44b8c78b4b6",
                "sha256": "51dececac4db8a51daa38abf9cde951822ee2796ed5d35c422a6f0ce935cd06d"
            },
            "downloads": -1,
            "filename": "mo_cache-0.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "03da5e36284a3a9b4ca9c44b8c78b4b6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8442,
            "upload_time": "2021-03-01T03:00:11",
            "upload_time_iso_8601": "2021-03-01T03:00:11.878329Z",
            "url": "https://files.pythonhosted.org/packages/c3/f1/26689a304c84b631464790d5a87a0da69e4eecfc3c657fb8e5b1ba66aa9a/mo_cache-0.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b720f9a90499a89827cf892f47e175d57494ed83987ab3c5d242b473d85eeffc",
                "md5": "e85ab233cd162dc8d6e8f7e421c88ac1",
                "sha256": "3fd1561dca04a8f780b50ca55d1d4ea66aa989405872ac7a638b50f98e3e8f87"
            },
            "downloads": -1,
            "filename": "mo-cache-0.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "e85ab233cd162dc8d6e8f7e421c88ac1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4699,
            "upload_time": "2021-03-01T03:00:14",
            "upload_time_iso_8601": "2021-03-01T03:00:14.212417Z",
            "url": "https://files.pythonhosted.org/packages/b7/20/f9a90499a89827cf892f47e175d57494ed83987ab3c5d242b473d85eeffc/mo-cache-0.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-03-01 03:00:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mouday",
    "github_project": "mo-cache",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "mo-cache"
}
        
Elapsed time: 0.25795s