Coder Social home page Coder Social logo

craiga / cachecontrol-django Goto Github PK

View Code? Open in Web Editor NEW

This project forked from glassesdirect/cachecontrol-django

0.0 1.0 0.0 16 KB

A cache provider for CacheControl using Django's caching mechanism.

Home Page: https://pypi.org/project/cachecontrol-django/

License: MIT License

Python 100.00%

cachecontrol-django's Introduction

cachecontrol-django

A cache provider for CacheControl using Django's caching mechanism.

PyPI Build Status Code style: black

Installation

pip install cachecontrol-django

Usage

import requests
from cachecontrol import CacheControl
from cachecontrol_django import DjangoCache

session = CacheControl(requests.session(), cache=DjangoCache())
session.get("https://www.glassesdirect.co.uk/")

Working Around Key Length Errors

If you see errors about key length (such as "MemcachedKeyLengthError: Key length is > 250"), you can ask DjangoCache to hash the keys it uses by specifying a key_hash_algorithm:

long_url = 'https://www.glassesdirect.co.uk/?q=' + ('x' * 250)
session = CacheControl(
    requests.session(),
    cache=DjangoCache(key_hash_algorithm='sha512')
)
session.get(long_url)

Note that when hashing these keys, there is a very small chance of a hash collision causing a request for one URL to return the content of another.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.