Caching POA #1454
Caching POA #1454
Changes from 1 commit
499ef24
3cc3bb4
6d5a2ee
c9fb769
eab9f32
f259b28
9fd7ae3
dc8c1f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Caching of data from ledger | ||
|
||
Currently whenever credential definitions and/or schemas is needed, it is being fetched from the ledger. | ||
This operation may last multiple seconds and is slowing down usage of credentials. | ||
Caching also enables usage of anoncreds in areas where user do not have internet coverage (eg. Using passport credential on foreign airport). | ||
|
||
## Goals and ideas | ||
|
||
* Allow users to cache credential definitions and schemas. | ||
* Local wallet to be used because although this data is public, possession of some credential definition or schema reveals possession of respective credential. | ||
* Provide higher level api for fetching this data so it is easier to use. | ||
* Caching should be transparent to the user. | ||
* Enable purging of old (not needed more) data. | ||
|
||
## Public API | ||
|
||
Note: In all calls `pool_handle` may be removed if did resolver is implemented. | ||
|
||
```Rust | ||
/// Gets credential definition json data for specified credential definition id. | ||
/// If data is present inside of cache, cached data is returned. | ||
/// Otherwise data is fetched from the ledger and stored inside of cache for future use. | ||
/// | ||
/// #Params | ||
/// command_handle: command handle to map callback to caller context. | ||
/// pool_handle: pool handle (created by open_pool_ledger). | ||
/// wallet_handle: wallet handle (created by open_wallet). | ||
/// submitter_did: DID of the submitter stored in secured Wallet. | ||
/// id: identifier of credential definition. | ||
/// cb: Callback that takes command result as parameter. | ||
#[no_mangle] | ||
pub extern fn indy_get_cred_def(command_handle: IndyHandle, | ||
pool_handle: IndyHandle, | ||
wallet_handle: IndyHandle, | ||
submitter_did: *const c_char, | ||
id: *const c_char, | ||
cb: Option<extern fn(command_handle_: IndyHandle, | ||
err: ErrorCode, | ||
cred_def_json: *const c_char)>) -> ErrorCode { | ||
} | ||
|
||
/// Gets schema json data for specified schema id. | ||
/// If data is present inside of cache, cached data is returned. | ||
/// Otherwise data is fetched from the ledger and stored inside of cache for future use. | ||
/// | ||
/// #Params | ||
/// command_handle: command handle to map callback to caller context. | ||
/// pool_handle: pool handle (created by open_pool_ledger). | ||
/// wallet_handle: wallet handle (created by open_wallet). | ||
/// submitter_did: DID of the submitter stored in secured Wallet. | ||
/// id: identifier of schema. | ||
/// cb: Callback that takes command result as parameter. | ||
#[no_mangle] | ||
pub extern fn indy_get_schema(command_handle: IndyHandle, | ||
pool_handle: IndyHandle, | ||
wallet_handle: IndyHandle, | ||
submitter_did: *const c_char, | ||
id: *const c_char, | ||
cb: Option<extern fn(command_handle_: IndyHandle, | ||
err: ErrorCode, | ||
schema_json: *const c_char)>) -> ErrorCode { | ||
} | ||
``` | ||
|
||
## Storing of the data into wallet | ||
|
||
Data would be stored with specific cache type so that it is separated and easy to be managed. | ||
Schema_id or cred_def_id would be used for id of wallet data. | ||
This way data may be fetched very efficiently and also easy to be deleted when needed. | ||
|
||
## Purging the cache | ||
|
||
Several methods may be implemented for purging the cached data: | ||
|
||
#### Purge all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we need to decide what exact option to use or provide an API for configuration of cache. For example, we can add behavior configuration to indy_init() method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To define purge behavior i also suggest to look to http cache options: Cache-Control: max-age=<seconds>
Cache-Control: max-stale[=<seconds>]
Cache-Control: min-fresh=<seconds>
Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: no-transform
Cache-Control: only-if-cached In this case we can define exact behavior for each entity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dkulic @jovfer @ashcherbakov @dhh1128 What do you think on ^? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure I follow your thoughts regarding defining exact behavior for each entity. Do you mean adding specific caching policy to each entity, so that purging process may selectively purge only entities which satisfy its own policy? If this is the case, that seams to complicated... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dkulic The idea is very simple:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds doable. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also purge can have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the timeout idea, because you may lock in some cache items in cache forever. (eg. so you may use your passport on foreign airport, without internet). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After some thoughts I figured out I do not like idea about purging on start/specifying ttl for every entity. I would expect that normally you would want data to be in cache for longer time, so you may during request choose max-age of data you want. I would modify it like this:
|
||
|
||
Advantages: | ||
* Very simple to implement. | ||
* Only one method would be needed (eg. `indy_purge_cache`). | ||
|
||
Disadvantages: | ||
* Low selectivity of purging | ||
|
||
#### Purge all of one type | ||
|
||
Advantages: | ||
* Very simple to implement. | ||
* Only one method per cache type is needed (eg. `indy_purge_cred_def_cache`). | ||
|
||
Disadvantages: | ||
* Low selectivity of purging | ||
|
||
#### LRU mechanism limited by size/number of cached data. | ||
|
||
Advantages: | ||
* Limited wallet data. | ||
* Only useful data is being kept, older not needed data is being purged automatically. | ||
|
||
Disadvantages: | ||
* Complex to implement. | ||
* Every fetching of data from cache would also introduce update of timestamp data (last used). | ||
|
||
Also some data can be locked-in to be always present (useful for out of internet scenario). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For freshness, I think that schema and credential_def cannot be updated (without change of id) so freshness is not needed. For that reason I do not see need for cache timestamp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my understanding CredDef and Schema can be updated. Schema can get backward compatible changes. Keys in CredDef can be rotated in some cases. Also some entities we plan to cache like DID Doc can be updated much often. @ashcherbakov What do you think?