cache_it-0.0.1
توضیحات
Decorators for caching
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | cache_it-0.0.1 |
| نام | cache_it |
| نسخه کتابخانه | 0.0.1 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Shoji Ihara |
| ایمیل نویسنده | shoji.ihara@gmail.com |
| آدرس صفحه اصلی | http://github.com/shoz/cache_it |
| آدرس اینترنتی | https://pypi.org/project/cache_it/ |
| مجوز | switchcache The MIT License Copyright (c) 2014 Shoji Ihara Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
cache_it
====
__cache_it__ is a decorator which wraps caching(read/write) routine.
Decorated functions automatically access your memcache and get/set values depending on the situation.
All you have to do is decorate your function by __@cache_it__.
## Basic Usage
```python
>>> from cache_it import init_cache, cache_it
>>> init_cache(['127.0.0.1:11211'])
>>> @cache_it(prefix='PREFIX:')
>>> def cached_function(key):
>>> return 'value'
>>> cached_function('key')
'value' # cached => key:'PREFIX:key' value:'value'
>>> cached_function('key')
'value' # getting from a cache
```
## As a method
You can decorate not only functions but also methods in the same way.
```python
class User(Document)
@cache_it(prefix='PREFIX')
def __getitem__(self, key):
return user[key]
```
## ignore_exception (False by default)
If you want to ignore exceptions occured when accessing memcache, you have to set "ignore_exception" into True.
```python
@cache_it(prefix='PREFIX', ignore_exception=True)
def cached_function(key):
return 'value'
```
## ttl (24*60*60 sec by default)
```python
@cache_it(prefix='PREFIX', ttl=60) # 60sec
def cached_function(key):
return 'value'
```
## encoder/decoder
Encoders are called before setting a value.
Decoders, on the other hand, are called after getting a value.
```python
@cache_it(prefix='PREFIX',
encoder=lambda x: x['foo'],
decoder=lambda x: {'foo': x})
def cached_function(key):
return {'foo': 'bar'}
```
نحوه نصب
نصب پکیج whl cache_it-0.0.1:
pip install cache_it-0.0.1.whl
نصب پکیج tar.gz cache_it-0.0.1:
pip install cache_it-0.0.1.tar.gz