Example #1
0
def test_load():
    cached = fscache.load(cache_file, mode='json')
    assert content['bytes'] == cached['bytes'].encode()
    assert content['datetime'] == parser.isoparse(cached['datetime'])  # datetime.fromisoformat requires Python 3.7
    assert content['decimal'] == decimal.Decimal(cached['decimal'])
    assert content['set'] == set(cached['set'])
    assert content['uuid'] == uuid.UUID(cached['uuid'])

    assert list(content['array']) == cached['array']
Example #2
0
def test_load():
    assert fscache.load(cache_file, mode='binary') == content
Example #3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from fscache import fscache

url = 'https://example.com/index.html'
cache_file = fscache.path(url, cache_dir='.fscache')

if fscache.valid(cache_file, lifetime=3600):
    content = fscache.load(cache_file)
    # Do something with content
else:
    content = requests.get(url).text
    # Save content in .fscache/https/example.com/index.html
    fscache.save(cache_file, content)
Example #4
0
def test_load():
    assert fscache.load(cache_file) == content