From 499ef240400260c954f7412b0c99cdf39f54d483 Mon Sep 17 00:00:00 2001 From: Darko Kulic Date: Tue, 5 Feb 2019 12:08:46 +0100 Subject: [PATCH 1/3] Caching POA Signed-off-by: Darko Kulic --- docs/design/013-caching/README.md | 103 ++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 docs/design/013-caching/README.md diff --git a/docs/design/013-caching/README.md b/docs/design/013-caching/README.md new file mode 100644 index 0000000000..1f4b36b597 --- /dev/null +++ b/docs/design/013-caching/README.md @@ -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) -> 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) -> 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 + +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). \ No newline at end of file From 6d5a2eee1d720db6b34cd102830f78d4c2757868 Mon Sep 17 00:00:00 2001 From: Darko Kulic Date: Wed, 6 Mar 2019 17:11:15 +0100 Subject: [PATCH 2/3] Updated document regarding options_json Signed-off-by: Darko Kulic --- docs/design/013-caching/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/design/013-caching/README.md b/docs/design/013-caching/README.md index 1f4b36b597..43191136e0 100644 --- a/docs/design/013-caching/README.md +++ b/docs/design/013-caching/README.md @@ -27,6 +27,10 @@ Note: In all calls `pool_handle` may be removed if did resolver is implemented. /// wallet_handle: wallet handle (created by open_wallet). /// submitter_did: DID of the submitter stored in secured Wallet. /// id: identifier of credential definition. +/// options_json: +/// { +/// forceUpdate: (optional, false by default) Force update of record in cache from the ledger, +/// } /// cb: Callback that takes command result as parameter. #[no_mangle] pub extern fn indy_get_cred_def(command_handle: IndyHandle, @@ -34,6 +38,7 @@ pub extern fn indy_get_cred_def(command_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: *const c_char, id: *const c_char, + options_json: *const c_char, cb: Option) -> ErrorCode { @@ -49,6 +54,10 @@ pub extern fn indy_get_cred_def(command_handle: IndyHandle, /// wallet_handle: wallet handle (created by open_wallet). /// submitter_did: DID of the submitter stored in secured Wallet. /// id: identifier of schema. +/// options_json: +/// { +/// forceUpdate: (optional, false by default) Force update of record in cache from the ledger, +/// } /// cb: Callback that takes command result as parameter. #[no_mangle] pub extern fn indy_get_schema(command_handle: IndyHandle, @@ -56,6 +65,7 @@ pub extern fn indy_get_schema(command_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: *const c_char, id: *const c_char, + options_json: *const c_char, cb: Option) -> ErrorCode { From f259b28e8c6b4cd4836cc20b6735ed63ab58207f Mon Sep 17 00:00:00 2001 From: Darko Kulic Date: Thu, 18 Apr 2019 12:06:32 +0200 Subject: [PATCH 3/3] Updated caching doc Signed-off-by: Darko Kulic --- docs/design/013-caching/README.md | 78 ++++++++++++++++++------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/docs/design/013-caching/README.md b/docs/design/013-caching/README.md index 43191136e0..e5cda5e04f 100644 --- a/docs/design/013-caching/README.md +++ b/docs/design/013-caching/README.md @@ -56,7 +56,10 @@ pub extern fn indy_get_cred_def(command_handle: IndyHandle, /// id: identifier of schema. /// options_json: /// { -/// forceUpdate: (optional, false by default) Force update of record in cache from the ledger, +/// noCache: (bool, optional, false by default) Skip usage of cache, +/// noUpdate: (bool, optional, false by default) Use only cached data, do not try to update. +/// noStore: (bool, optional, false by default) Skip storing fresh data if updated, +/// minFresh: (int, optional, -1 by default) Return cached data if not older than this many seconds. -1 means do not check age. /// } /// cb: Callback that takes command result as parameter. #[no_mangle] @@ -70,6 +73,47 @@ pub extern fn indy_get_schema(command_handle: IndyHandle, err: ErrorCode, schema_json: *const c_char)>) -> ErrorCode { } + +/// Purge credential definition cache. +/// +/// #Params +/// command_handle: command handle to map callback to caller context. +/// wallet_handle: wallet handle (created by open_wallet). +/// id: identifier of schema. +/// options_json: +/// { +/// minFresh: (int, optional, -1 by default) Purge cached data if older than this many seconds. -1 means purge all. +/// } +/// cb: Callback that takes command result as parameter. +#[no_mangle] +pub extern fn indy_purge_cred_def_cache(command_handle: IndyHandle, + wallet_handle: IndyHandle, + options_json: *const c_char, + cb: Option) -> ErrorCode { + +} + +/// Purge schema cache. +/// +/// #Params +/// command_handle: command handle to map callback to caller context. +/// wallet_handle: wallet handle (created by open_wallet). +/// id: identifier of schema. +/// options_json: +/// { +/// maxAge: (int, mandatory) Purge cached data if older than this many seconds. -1 means purge all. +/// } +/// cb: Callback that takes command result as parameter. +#[no_mangle] +pub extern fn indy_purge_schema_cache(command_handle: IndyHandle, + wallet_handle: IndyHandle, + options_json: *const c_char, + cb: Option) -> ErrorCode { + +} + ``` ## Storing of the data into wallet @@ -80,34 +124,4 @@ This way data may be fetched very efficiently and also easy to be deleted when n ## Purging the cache -Several methods may be implemented for purging the cached data: - -#### Purge all - -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). \ No newline at end of file +Data may be purged if older than some number of seconds.