Metadata-Version: 2.4
Name: diskoize
Version: 0.1.1
Summary: A memoize-like decorator that caches to disk.
Author-email: Erik Aas <esraiak@gmail.com>
License: Copyright (c) 2018 The Python Packaging Authority
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/esraiak/diskoize
Project-URL: Issues, https://github.com/esraiak/diskoize/issues
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

diskoize:memoize::disk:memory

# What is this

Often when I use @functools.lru_cache I find that the cache is erased between python process restarts. This library is the fix!

```bash
import diskoize
import requests

@diskoize.diskoize("scrape_cache.db")
def scrape(url):
  return requests.request(url)


scrape("google.com") # <-- will run only once, even after rerunning this script.
```

You need to manually delete the cache if you change the function's input-output behavior.



# Tests

We use pytest for testing. To run the tests, you can use the following command:

```bash
pytest
```
This will run all the tests in the `tests` directory. You can also run a specific test file by providing the path to the file:

```bash
pytest tests/test_file.py
```

# Development

Make a temporary pip install: pip install -e .
Now you can use the library from any python script, and edits to the local diskoize/ folder will be reflected.

# Remarks

* There is a tension between making this library understandable and making it easy to use.
  -- we always give the option of explicitly naming the backing sqlite database file.
  -- for autonaming, we currently create or reuse a file in the system temp directory which is based 
  based on the diskoized function's __name__. It is up to the user to delete invalidated caches. So autonaming should probably only be used for quick-and-dirty experiments where we don't expect to come back to the code after a long while. 


# TODOs

* add option in_memory (default False) to store the cache in memory, always with persistent backing.
* make the tests actually test separate processes accessing the same cache
* add methods for interacting with the cache
* add more examples
* add flush() method, and a lru_cache to support it
* fix _make_key
