Merge branch 'master' of github.com:shaypal5/cachier

forgot to pull readme changes... :)
This commit is contained in:
Shay Palachy
2017-04-25 00:12:25 +03:00
+22 -13
View File
@@ -66,7 +66,7 @@ The positional and keyword arguments to the wrapped function must be hashable (i
Setting up a Cache
------------------
You can add a deafult, pickle-based, persistent cache to your function - meaning it will last across different Python kernels calling the wrapped function - by decorating it with the ``cachier`` decorator (notice the ``()``!).
You can add a default, pickle-based, persistent cache to your function - meaning it will last across different Python kernels calling the wrapped function - by decorating it with the ``cachier`` decorator (notice the ``()``!).
.. code-block:: python
@@ -104,11 +104,11 @@ You can set any duration as the shelf life of cached return values of a function
Now when a cached value matching the given arguments is found the time of its calculation is checked; if more than ``stale_after`` time has since passed, the function will be run again for the same arguments and the new value will be cached and returned.
This is usefull for lengthy calculations that depend on a dynamic data source.
This is useful for lengthy calculations that depend on a dynamic data source.
Fuzzy Shelf Life
~~~~~~~~~~~~~~~~
Sometimes you may want your function to trigger a calculation when it encounters a stale result, but still not wait on it if it's not that critical. In that case you can set ``next_time`` to ``True`` to have your function trigger a recalculation **in a separate thread**, but return the currently cached stale value:
Sometimes you may want your function to trigger a calculation when it encounters a stale result, but still not wait on it if it's not that critical. In that case, you can set ``next_time`` to ``True`` to have your function trigger a recalculation **in a separate thread**, but return the currently cached stale value:
.. code-block:: python
@@ -120,12 +120,12 @@ Further function calls made while the calculation is being performed will not tr
Per-function call arguments
---------------------------
Cachier also accepts several keyword arguments in the calls of the function it wraps rather than in the decorator call, allowing to modify its behaviour for a specific function call.
Cachier also accepts several keyword arguments in the calls of the function it wraps rather than in the decorator call, allowing you to modify its behaviour for a specific function call.
Ignore Cache
~~~~~~~~~~~~
You cah have ``cachier`` ignore any existing cache for a specific function call by passing ``ignore_cache=True`` to the function call. The cache will neither be checked nor updated with the new return value.
You can have ``cachier`` ignore any existing cache for a specific function call by passing ``ignore_cache=True`` to the function call. The cache will neither be checked nor updated with the new return value.
.. code-block:: python
@@ -139,12 +139,12 @@ You cah have ``cachier`` ignore any existing cache for a specific function call
Overwrite Cache
~~~~~~~~~~~~~~~
You cah have ``cachier`` overwrite an existing cache entry - if one exists - for a specific function call by passing ``overwrite_cache=True`` to the function call. The cache will not be checked, but will be updated with the new return value.
You can have ``cachier`` overwrite an existing cache entry - if one exists - for a specific function call by passing ``overwrite_cache=True`` to the function call. The cache will not be checked but will be updated with the new return value.
Verbose Cache Call
~~~~~~~~~~~~~~~~~~
You cah have ``cachier`` print out a detailed explanation of the logic of a specific call by passing ``verbose_cachee=True`` to the function call. This can be usefull if you are not sure why a certain function result is or is not returned.
You can have ``cachier`` print out a detailed explanation of the logic of a specific call by passing ``verbose_cache=True`` to the function call. This can be useful if you are not sure why a certain function result is, or is not, returned.
@@ -154,20 +154,20 @@ Cachier Cores
Pickle Core
-----------
The default core for Cachier is pickle based, meaning each function will store its cache is a seperate pickle file in the ``~/.cachier`` directory. Naturally, this kind of cache is both machine-specific and user-specific.
The default core for Cachier is pickle based, meaning each function will store its cache is a separate pickle file in the ``~/.cachier`` directory. Naturally, this kind of cache is both machine-specific and user-specific.
You can slightly optimize pickle-based caching if you know your code will only be used in a single thread environment by setting:
You can slightly optimise pickle-based caching if you know your code will only be used in a single thread environment by setting:
.. code-block:: python
@cachier(pickle_reload=False)
This will prevent reading the cache file on each cache read, speeding things up a bit, while also nullfying inter-thread functionality (the code is still thread safe, but different threads will have different versions of the cache at times, and will sometime make unecessary function calls).
This will prevent reading the cache file on each cache read, speeding things up a bit, while also nullifying inter-thread functionality (the code is still thread safe, but different threads will have different versions of the cache at times, and will sometime make unnecessary function calls).
MongoDB Core
------------
You can set a MongoDB-based cache by assigning ``mongetter`` with a callable that returns a ``pymongo.Collection`` object with writing permission:
You can set a MongoDB-based cache by assigning ``mongetter`` with a callable that returns a ``pymongo.Collection`` object with writing permissions:
.. code-block:: python
@@ -202,7 +202,7 @@ Install in development mode with test dependencies:
Running the tests
-----------------
To run the tests use:
To run the tests, use:
.. code-block:: bash
@@ -212,7 +212,7 @@ To run the tests use:
Adding documentation
--------------------
This project is documented using the `numpy docstring conventions`_, which were chosen as they are perhaps the most widely-spread conventions that are both supported by common tools such as Sphinx and result in human-readable docstrings. When documenting code you add to this project, please follow `these conventions`_.
This project is documented using the `numpy docstring conventions`_, which were chosen as they are perhaps the most widely-spread conventions that are both supported by common tools such as Sphinx and result in human-readable docstrings (in my personal opinion, of course). When documenting code you add to this project, please follow `these conventions`_.
.. _`numpy docstring conventions`: https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
.. _`these conventions`: https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
@@ -222,6 +222,15 @@ Credits
=======
Created by Shay Palachy (shay.palachy@gmail.com).
Contributers (in chronological order of first commit):
* `shaypal5`_ (Shay Palachy)
* `j-chad`_ (Jackson)
.. Contributer links:
.. _shaypal5: https://github.com/shaypal5
.. _j-chad: https://github.com/j-chad
.. |PyPI-Status| image:: https://img.shields.io/pypi/v/cachier.svg