Skip to content

Commit

Permalink
improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Oct 27, 2023
1 parent a0c7ec8 commit c1fc5b7
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,59 @@ False

```

### Cache files

```python
>>> import cacholote

>>> import tempfile
>>> tmpdir = tempfile.TemporaryDirectory().name
>>> cacholote.config.set(
... cache_db_urlpath="sqlite://",
... cache_files_urlpath=tmpdir,
... )
<cacholote.config.set ...

>>> cached_open = cacholote.cacheable(open)
>>> cached_file = cached_open("README.md")
>>> cached_file.name.startswith(tmpdir)
True

>>> import filecmp
>>> filecmp.cmp("README.md", cached_file.name)
True

```

### Cache xarray datasets

```python
>>> import cacholote

>>> import tempfile
>>> tmpdir = tempfile.TemporaryDirectory().name
>>> cacholote.config.set(
... cache_db_urlpath="sqlite://",
... cache_files_urlpath=tmpdir,
... )
<cacholote.config.set ...

>>> @cacholote.cacheable
... def dataset_from_dict(ds_dict):
... import xarray as xr
... return xr.Dataset(ds_dict)
>>> ds = dataset_from_dict({"foo": 0})
>>> ds
<xarray.Dataset>
Dimensions: ()
Data variables:
foo int64 ...

>>> ds.encoding["source"].startswith(tmpdir)
True

```

## Configuration

Configuration settings can be accessed using `cacholote.config.get()` and modified using `cacholote.config.set(**kwargs)`. It is possible to use `cacholote.config.set` either as a context manager, or to configure global settings. See `help(cacholote.config.set)`.
Expand Down

0 comments on commit c1fc5b7

Please sign in to comment.