-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature cache #2959
Merged
Merged
Feature cache #2959
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- adding deprecation for few old methods - removing deprecated code from entity manager Signed-off-by: riccardomodanese <riccardo.modanese@eurotech.com>
Signed-off-by: Gianluca Barbon <gianluca.barbon@eurotech.com>
Signed-off-by: Gianluca Barbon <gianluca.barbon@eurotech.com>
Signed-off-by: Gianluca Barbon <gianluca.barbon@eurotech.com>
Signed-off-by: Gianluca Barbon <gianluca.barbon@eurotech.com>
Signed-off-by: Gianluca Barbon <gianluca.barbon@eurotech.com>
…ove to dependdency management root pom section Signed-off-by: riccardomodanese <riccardo.modanese@eurotech.com>
Codecov Report
@@ Coverage Diff @@
## develop #2959 +/- ##
=============================================
+ Coverage 55.92% 56.24% +0.31%
- Complexity 2557 2592 +35
=============================================
Files 1044 1059 +15
Lines 22692 22975 +283
Branches 2036 2061 +25
=============================================
+ Hits 12691 12922 +231
- Misses 9067 9106 +39
- Partials 934 947 +13
|
riccardomodanese
force-pushed
the
feature-cache
branch
from
April 30, 2020 10:14
828cb17
to
e14a64e
Compare
Coduz
approved these changes
Apr 30, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a caching feature at the service level. This implementation is compliant with the JCache specification, meaning that each cache that implements the JCache interface can be used with this caching feature.
The cache is implemented a given set of services, in order to improve performances. A simple JCache implementation based on HashMaps is also provided, in order to test the caching feature with the QAs.
Related Issue
N/A
Description of the solution adopted
The package
org.eclipse.kapua.commons.service.internal.cache
contains theKapuaCacheManager
, which is responsible for instantiating a cache for each service, and theEntityCache
class, which defines our basic cache implementation (using entities Ids as keys) on top of JCache.NamedEntityCache
extendsEntityCache
by providing an additional cache (using entities names as keys).The cache allows avoiding repeated queries to the database, in particular when checking permissions to perform an action on a given method. As an example, the
checkPermission
method of theAuthorizationService
(responsible for checking if an user is allowed to perform a given operation), performs a chain of calls to theUserService
,AccessInfoService
,AccessPermissionService
,AccessRoleService
,RoleService
andRolePermissionService
services, each of which performs a query to the db. Caching all these services allows considerably reducing the time spent on querying the db.Also, note that the message processing by the broker requires methods from the
AccountService
andDeviceRegistryService
, which both perform transactions to the database. Such transactions are performed for each message received by the broker, thus using a cache on those services allows reducing queries when the same data is required.The QAs will make use of an in-memory HashMaps-based implementation of JCache in order to mimic the behaviour of a real cache instance. In order to mimic the serialisation, this cache is also provided with a clone method which performs a deep clone of the given entity in
put
andget
operations.Screenshots
N/A
Any side note on the changes made
Note also that this cache feature requires a JCache implementation to run, otherwise a 'dummy' cache is used.
Services require to be modified in order to implement the cache. The following services have been cached:
AccessInfoService
AccessPermissionService
AccessRoleService
AccountService
DeviceConnectionService
DeviceRegistryService
RoleService
RolePermissionService
UserService
Each service is able to instantiate is own cache through a dedicated cache factory. However, note that
DeviceConnectionService
is not using a dedicated cache factory, but it relies on theDeviceRegistryCacheFactory
. Moreover, also theAbstractKapuaConfigurableService
has been provided with a cache instance, in order to cache the configuration values for each services. ALocalCache
instance (which must not be confused with a JCache cache instance) has also been added in order to store the config metadata, which do not change after the first time the object is loaded.The JCache implementation for the QAs is enabled trough the following property
commons.cache.provider.classname=org.eclipse.kapua.qa.common.cache.MapCachingProvider