Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kryptonbutterfly/tinycache-example
an Example for the tinyCache library and the CacheBuilder ByteCode manipulator
https://github.com/kryptonbutterfly/tinycache-example
Last synced: 8 days ago
JSON representation
an Example for the tinyCache library and the CacheBuilder ByteCode manipulator
- Host: GitHub
- URL: https://github.com/kryptonbutterfly/tinycache-example
- Owner: kryptonbutterfly
- License: apache-2.0
- Created: 2022-09-19T14:35:33.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-19T15:40:16.000Z (about 2 years ago)
- Last Synced: 2024-01-18T23:13:47.465Z (10 months ago)
- Language: Java
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tinyCache Example
This is an example of the tinyCache library in combination with CacheBuilder ByteCode manipulator.
## Components
Description | Project
:------------------- | :------
dependency | [tinyCache](https://github.com/tinycodecrank/tinyCache)
bytecode manipulator | [CacheBuilder](https://github.com/tinycodecrank/CacheBuilder)## Example
```java
static int invocations = 0;@Cache(cache = FIFOCache.class, capacity = 2)
public static int fibonacci(int n)
{
invocations++;
if (n == 0 || n == 1)
return n;
else
return fibonacci(n - 2) + fibonacci(n - 1);
}public void main(String[] args)
{
int n = 10;
System.out.println("fibonacci(" + n + ") => " + fibonacci(n));
System.out.println("invocations " + invocations);
}
```##### Output
```shell
fibonacci(10) => 55
invocations 11
```In this example the @Cache annotation causes the function ```int fibonacci(int n)``` to be wrapped in a FIFO cache with capacity 2, avoiding recomputation of already computed values.
This reduces the invocation count for a given n ∊ ℕ from ≈2n to ≈n