peterbe / django-cache-memoize
Showing 1 of 3 files from the diff.
Other files ignored by Codecov

@@ -18,6 +18,7 @@
Loading
18 18
    miss_callable=None,
19 19
    key_generator_callable=None,
20 20
    store_result=True,
21 +
    cache_exceptions=(),
21 22
    cache_alias=DEFAULT_CACHE_ALIAS,
22 23
):
23 24
    """Decorator for memoizing function calls where we use the
@@ -33,6 +34,11 @@
Loading
33 34
    :arg key_generator_callable: Custom cache key name generator.
34 35
    :arg bool store_result: If you know the result is not important, just
35 36
    that the cache blocked it from running repeatedly, set this to False.
37 +
    :arg Exception cache_exceptions: Accepts an Exception or a tuple of
38 +
    Exceptions. If the cached function raises any of these exceptions is the
39 +
    exception cached and raised as normal. Subsequent cached calls will
40 +
    immediately re-raise the exception and the function will not be executed.
41 +
    this tuple will be cached, all other will be propagated.
36 42
    :arg string cache_alias: The cache alias to use; defaults to 'default'.
37 43
38 44
    Usage::
@@ -117,7 +123,14 @@
Loading
117 123
            else:
118 124
                result = cache.get(cache_key, MARKER)
119 125
            if result is MARKER:
120 -
                result = func(*args, **kwargs)
126 +
127 +
                # If the function all raises an exception we want to cache,
128 +
                # catch it, else let it propagate.
129 +
                try:
130 +
                    result = func(*args, **kwargs)
131 +
                except cache_exceptions as exception:
132 +
                    result = exception
133 +
121 134
                if not store_result:
122 135
                    # Then the result isn't valuable/important to store but
123 136
                    # we want to store something. Just to remember that
@@ -129,6 +142,11 @@
Loading
129 142
                    miss_callable(*args, **kwargs)
130 143
            elif hit_callable:
131 144
                hit_callable(*args, **kwargs)
145 +
146 +
            # If the result is an exception we've caught and cached, raise it
147 +
            # in the end as to not change the API of the function we're caching.
148 +
            if isinstance(result, Exception):
149 +
                raise result
132 150
            return result
133 151
134 152
        def invalidate(*args, **kwargs):
Files Coverage
src/cache_memoize/__init__.py 100.00%
Project Totals (1 files) 100.00%
99.3
3.7=.7
TRAVIS_OS_NAME=linux
99.1
3.5=.5
TRAVIS_OS_NAME=linux
99.4
TRAVIS_OS_NAME=linux
pypy3=
99.2
3.6=.6
TRAVIS_OS_NAME=linux

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading