Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
howie6879 committed Mar 6, 2018
1 parent 409baf9 commit 12f7446
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 1 deletion.
105 changes: 105 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
.idea/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
.html/
# C extensions
*.so

# Distribution / packaging
.Python
env/
env27/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
/tests/data.sqlite
/examples/toapi-pic/data.sqlite
74 changes: 73 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,76 @@

![PyPI](https://img.shields.io/pypi/v/expire.svg)

Expire aims to make using cache as convenient as possible.
## What is Expire

When you are writing a service, maybe you need to be able to save a piece of JSON data to your system's memory.

Expire aims to make using cache as convenient as possible.

There are three ways to create a cache, which are MemoryCache, RedisCache or MemcachedCache.

## How to Use?

### Installation

**Run:**

``` shell
pip install expire

pip install git+https://github.com/howie6879/expire.git
```

### Usage

**MemoryCache:** easy to configure, but it automatically destroys when the server is stopped.

``` python
from expire import CacheSetting, MemoryCache

memory_cache = MemoryCache()
memory_cache.set('name', 'expire')
cache_ins = CacheSetting()
print(cache_ins.get('name'))

# Output: expire
```

**RedisCache:** stable but you have to install Redis.

``` python
from expire import Settings
from expire import RedisCache, cached, CacheSetting

class MySettings(Settings):
"""
Create custom configuration
"""
cache = {
# RedisCache, MemoryCache or MemcachedCache
'cache_class': RedisCache,
'cache_config': {
'host': '127.0.0.1',
'port': 6379,
'db': 0,
'password': None
},
# JsonSerializer, PickleSerializer or StrSerializer
'serializer': None
}
@cached(**MySettings.cache, ttl=1000)
def parse(url, params=None, **kwargs):
return "{0}: {1}".format(url, 'hello')


def cached_by_redis(key):
cache_ins = CacheSetting(MySettings)
return cache_ins.get(key)

key = 'expire'
result = parse(url=key, dynamic_key=key)
print(result)
# Output 'expire: hello'
print(cached_by_redis(key))
# Output 'expire: hello'
```

0 comments on commit 12f7446

Please sign in to comment.