Skip to content

Commit

Permalink
Merge pull request #14 from cr0hn/feature/setup-gitlab-pipeline-and-p…
Browse files Browse the repository at this point in the history
…oetry

Feature/setup gitlab pipeline and poetry
  • Loading branch information
cr0hn committed Jan 30, 2020
2 parents 936f051 + 744455b commit 5f5c00b
Show file tree
Hide file tree
Showing 39 changed files with 923 additions and 1,213 deletions.
20 changes: 0 additions & 20 deletions .circleci/config.yml

This file was deleted.

1 change: 0 additions & 1 deletion .env.example

This file was deleted.

7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
application-import-names = platform_mcs
import-order-style = smarkets
inline-quotes = double
max-complexity = 15
multiline-quotes = double
ignore=I101, P101
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@ ENV/
.spyderproject

# Rope project settings
.ropeproject
.ropeproject
.idea/
38 changes: 38 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
image: tmaier/docker-compose:18.09
services:
- docker:18.09-dind

before_script:
- docker version
- docker-compose version

after_script:
- docker images

stages:
- lint
- test
- deploy

lint:
stage: lint
image: python:3.7
before_script:
- pip install pre-commit
script:
- pre-commit run -av

test:
stage: test
script:
- docker-compose run tests

deploy:pypi:
stage: deploy
image: python:3.7
before_script:
- pip install poetry
script:
- poetry publish -u $PYPI_U -p $PYPI_P --build
only:
- master
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
exclude: >
(?x)^(
tests/data/.*|
.*\.svg
)$
minimum_pre_commit_version: 1.13.0
repos:
- repo: https://github.com/ambv/black
rev: 19.10b0
hooks:
- id: black
args: [--line-length=79]
exclude: ^tests/.*$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
name: Lint code (flake8)
additional_dependencies:
- flake8==3.7.9
- flake8-broken-line==0.1.1
- flake8-bugbear==19.8.0
- flake8-builtins==1.4.1
- flake8-comprehensions==3.0.1
- flake8-import-order==0.18.1
- flake8-mutable==1.2.0
- flake8-quotes==2.1.0
- flake8-string-format==0.2.3
- flake8-tidy-imports==3.0.0
- pep8-naming==0.8.2
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Improvements and fixes
New features
------------

- First Version
- First Version
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM python:3.7 as base

FROM base as install-deps
WORKDIR /aiohttp-cache

COPY ./requirements.txt .
COPY ./requirements-test.txt .
FROM base as install-poetry
RUN pip install poetry

RUN pip install -r requirements.txt
RUN pip install -r requirements-test.txt
FROM install-poetry as install-deps
WORKDIR /aiohttp-cache
COPY ./pyproject.toml .
COPY ./poetry.lock .
RUN poetry install

FROM install-deps as copy-src
COPY . .

ENTRYPOINT ["poetry", "run"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ global-exclude *.pyd
global-exclude *.pyc
global-exclude .git*
global-exclude .DS_Store
global-exclude .mailmap
global-exclude .mailmap
144 changes: 144 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Aiohttp-cache
title: 'aiohttp-cache'
---

![aiohttp-cache logo](https://raw.githubusercontent.com/cr0hn/aiohttp-cache/master/doc/source/_static/aiohttp-cache-128x128.png)


# What's aiohttp-cache

`aiohttp-cache` is a plugin for aiohttp.web server that allow to use a
cache system to improve the performance of your site.

# How to use it

## With in-memory backend

```python
import asyncio

from aiohttp import web

from aiohttp_cache import ( # noqa
setup_cache,
cache,
)

PAYLOAD = {"hello": "aiohttp_cache"}
WAIT_TIME = 2


@cache()
async def some_long_running_view(request: web.Request) -> web.Response:
await asyncio.sleep(WAIT_TIME)
payload = await request.json()
return web.json_response(payload)


app = web.Application()
setup_cache(app)
app.router.add_post("/", some_long_running_view)

web.run_app(app)
```

## With redis backend

**Note**: redis should be available at
`$CACHE_URL` env variable or`redis://localhost:6379/0`

```python
import asyncio

import yarl
from aiohttp import web
from envparse import env

from aiohttp_cache import ( # noqa
setup_cache,
cache,
RedisConfig,
)

PAYLOAD = {"hello": "aiohttp_cache"}
WAIT_TIME = 2


@cache()
async def some_long_running_view(request: web.Request) -> web.Response:
await asyncio.sleep(WAIT_TIME)
payload = await request.json()
return web.json_response(payload)


app = web.Application()
url = yarl.URL(env.str("CACHE_URL", default="redis://localhost:6379/0"))
setup_cache(
app,
cache_type="redis",
backend_config=RedisConfig(
db=int(url.path[1:]), host=url.host, port=url.port
),
)

app.router.add_post("/", some_long_running_view)

web.run_app(app)
```

## Example with a custom cache key

Let's say you would like to cache the requests just by the method and
json payload, then you can setup this as per the follwing example.

**Note** default key_pattern is:

```python
DEFAULT_KEY_PATTERN = (
AvailableKeys.method,
AvailableKeys.host,
AvailableKeys.path,
AvailableKeys.postdata,
AvailableKeys.ctype,
)
```

```python
import asyncio

from aiohttp import web

from aiohttp_cache import setup_cache, cache, AvailableKeys # noqa

PAYLOAD = {"hello": "aiohttp_cache"}
WAIT_TIME = 2


@cache()
async def some_long_running_view(request: web.Request) -> web.Response:
await asyncio.sleep(WAIT_TIME)
payload = await request.json()
return web.json_response(payload)


custom_cache_key = (AvailableKeys.method, AvailableKeys.json)

app = web.Application()
setup_cache(app, key_pattern=custom_cache_key)
app.router.add_post("/", some_long_running_view)

web.run_app(app)
```

# License

This project is released under BSD license. Feel free

# Source Code

The latest developer version is available in a github repository:
<https://github.com/cr0hn/aiohttp-cache>

# Development environment

1. docker-compose run tests
45 changes: 0 additions & 45 deletions README.rst

This file was deleted.

19 changes: 13 additions & 6 deletions aiohttp_cache/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from .setup import *
from .backends import *
from .decorators import *
from .middleware import *
from .exceptions import *
from .backends import AvailableKeys, MemoryCache, RedisCache, RedisConfig
from .decorators import cache
from .middleware import cache_middleware
from .setup import setup_cache

__version__ = "1.0.3"

__all__ = (
"AvailableKeys",
"MemoryCache",
"RedisCache",
"RedisConfig",
"cache",
"cache_middleware",
"setup_cache",
)

0 comments on commit 5f5c00b

Please sign in to comment.