m-caching


Namem-caching JSON
Version 0.1.15 PyPI version JSON
download
home_pageNone
SummarySetup normal class to mobio lru cache
upload_time2024-04-08 09:48:53
maintainerNone
docs_urlNone
authorMOBIO
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # <h2 id="title">LRU Cache</h2>
Thư viện caching của MOBIO. Hỗ trợ cache trên memory hoặc Redis.

#### Cài đặt:
`pip3 install m-caching`

#### Sử dụng:
```
__store_type = StoreType.REDIS # for redis cache
__store_type = StoreType.LOCAL # for memory cache
__file_config = 'config-file-path'

lru_redis_cache = LruCache(store_type=__store_type, config_file_name=__file_config,
                           redis_uri='redis://redis:6379/0',
                           redis_cluster_uri='redis://redis-cluster.redis.svc.cluster.local:6379/0',
                           redis_type=RedisType.REPLICA)

```
Ignore empty values from cache
```
__store_type = StoreType.REDIS
__file_config = 'config-file-path'
lru_cache = LruCache(store_type=__store_type, config_file_name=__file_config)
lru_cache.accept_none(False) # => ignore none values
``` 

#### Usage
cache for class's function
```
class TestCache:
    @lru_cache.add_for_class()
    def test(self, x):
        print("TestCache::test param %s" % x)
        return x + 1

    @staticmethod
    @lru_cache.add()
    def test_static(x):
        print("TestCache::test_static test param %s" % x)
        return x + 1
        
    @staticmethod
    @lru_cache.add_async()
    async def test_static_async(x):
        print("TestCache::test_static test param %s" % x)
        return x + 1
       
    @lru_cache.add_for_class_async()
    async def test_async(self, x):
        print("TestCache::test param %s" % x)
        return x + 1
```

cache for normal function
```
@lru_cache.add()
def some_expensive_method(x):
    print("Calling some_expensive_method(" + str(x) + ")")
    return x + 200
```

#### Example config
```
[REDIS]
host=redis-server
port=6379
cache_prefix=test_cache
```

#### Changedlog:

##### v0.1.14:
- Support Function Async

##### v0.1.13:
- Support RedisCluster

##### v0.1.12:
- Fix bug: missing import;

##### v0.1.11:
- Support python3.9

##### v0.1.10:
- Sửa lại tên version 0.1.9

##### v0.1.9:
- Thêm try...except: khi set item vao redis.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "m-caching",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "MOBIO",
    "author_email": "contact@mobio.io",
    "download_url": "https://files.pythonhosted.org/packages/37/8d/e01f0cdd953cdc7b8d60d24ed051e14d61ce5a41aa7d065192bfd46b5455/m-caching-0.1.15.tar.gz",
    "platform": null,
    "description": "# <h2 id=\"title\">LRU Cache</h2>\nTh\u01b0 vi\u1ec7n caching c\u1ee7a MOBIO. H\u1ed7 tr\u1ee3 cache tr\u00ean memory ho\u1eb7c Redis.\n\n#### C\u00e0i \u0111\u1eb7t:\n`pip3 install m-caching`\n\n#### S\u1eed d\u1ee5ng:\n```\n__store_type = StoreType.REDIS # for redis cache\n__store_type = StoreType.LOCAL # for memory cache\n__file_config = 'config-file-path'\n\nlru_redis_cache = LruCache(store_type=__store_type, config_file_name=__file_config,\n                           redis_uri='redis://redis:6379/0',\n                           redis_cluster_uri='redis://redis-cluster.redis.svc.cluster.local:6379/0',\n                           redis_type=RedisType.REPLICA)\n\n```\nIgnore empty values from cache\n```\n__store_type = StoreType.REDIS\n__file_config = 'config-file-path'\nlru_cache = LruCache(store_type=__store_type, config_file_name=__file_config)\nlru_cache.accept_none(False) # => ignore none values\n``` \n\n#### Usage\ncache for class's function\n```\nclass TestCache:\n    @lru_cache.add_for_class()\n    def test(self, x):\n        print(\"TestCache::test param %s\" % x)\n        return x + 1\n\n    @staticmethod\n    @lru_cache.add()\n    def test_static(x):\n        print(\"TestCache::test_static test param %s\" % x)\n        return x + 1\n        \n    @staticmethod\n    @lru_cache.add_async()\n    async def test_static_async(x):\n        print(\"TestCache::test_static test param %s\" % x)\n        return x + 1\n       \n    @lru_cache.add_for_class_async()\n    async def test_async(self, x):\n        print(\"TestCache::test param %s\" % x)\n        return x + 1\n```\n\ncache for normal function\n```\n@lru_cache.add()\ndef some_expensive_method(x):\n    print(\"Calling some_expensive_method(\" + str(x) + \")\")\n    return x + 200\n```\n\n#### Example config\n```\n[REDIS]\nhost=redis-server\nport=6379\ncache_prefix=test_cache\n```\n\n#### Changedlog:\n\n##### v0.1.14:\n- Support Function Async\n\n##### v0.1.13:\n- Support RedisCluster\n\n##### v0.1.12:\n- Fix bug: missing import;\n\n##### v0.1.11:\n- Support python3.9\n\n##### v0.1.10:\n- S\u1eeda l\u1ea1i t\u00ean version 0.1.9\n\n##### v0.1.9:\n- Th\u00eam try...except: khi set item vao redis.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Setup normal class to mobio lru cache",
    "version": "0.1.15",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "378de01f0cdd953cdc7b8d60d24ed051e14d61ce5a41aa7d065192bfd46b5455",
                "md5": "20b2ae4a33d27ec9eb7f118c667454ba",
                "sha256": "06496bd9718b973352822905b0f9230e4a58842f70914b0cdba53cd6aedccfe3"
            },
            "downloads": -1,
            "filename": "m-caching-0.1.15.tar.gz",
            "has_sig": false,
            "md5_digest": "20b2ae4a33d27ec9eb7f118c667454ba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7351,
            "upload_time": "2024-04-08T09:48:53",
            "upload_time_iso_8601": "2024-04-08T09:48:53.100345Z",
            "url": "https://files.pythonhosted.org/packages/37/8d/e01f0cdd953cdc7b8d60d24ed051e14d61ce5a41aa7d065192bfd46b5455/m-caching-0.1.15.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-08 09:48:53",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "m-caching"
}
        
Elapsed time: 0.24268s