Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
dalum committed Jul 29, 2020
1 parent 34f0d14 commit bdd32c8
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Build Status](https://travis-ci.org/dalum/Purses.jl.svg?branch=master)](https://travis-ci.org/dalum/Purses.jl)
[![codecov](https://codecov.io/gh/dalum/Purses.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/dalum/Purses.jl)

This package provides a simple and extensible type for wrapping a value that carries a small cache around with it—a purse. The cache is stored internally as a tuple, and the functions used for caching the entries are saved as a type parameter. This allows specialising on the function to retrieve the cached value using compile-time constants for indexing into the cache.
This package provides a simple and extensible type for wrapping a value that carries a small cache around with it—a purse. The cache is stored internally as a tuple, and the functions used for caching the entries are saved as a type parameter. This allows specialising on the function to retrieve the cached value using compile-time constants for indexing into the cache. Note that the default implementation, `Purse`, is assumed to be immutable. Mutations of a wrapped mutable object is explicitly unsupported at this moment.

# Usage

Expand Down Expand Up @@ -46,7 +46,3 @@ julia> @btime (sqrt∘sum)($(Ref(purse))[])
71.19071328707443
```
Note, however, in order to take advantage of this, the type of the purse must be inferable at the call site. In other words, the type of the purse must be known at compile time, otherwise Julia will have to use dynamic dispatch to retrieve the value. This can often lead to orders of magnitudes in loss of performance.

## Registering functions

To be able to use the cached result of a function, the function must first be registered. This happens automatically for each of the function parameters passed to a `Purse`, when it is created. Sometimes, you may have to call a non-generic function on the purse, however. To avoid type piracy, such an instance should be resolved by letting `Purses.jl` define the method using the `register!` function. Note, however, that this will define a generic method for `AbstractPurse` which will automatically unwrap the purse into the function, when a cache isn't found. This may be fixed in future versions.

0 comments on commit bdd32c8

Please sign in to comment.