-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introducing cache for the database metadata requests from WebIDE
- Loading branch information
Showing
8 changed files
with
216 additions
and
9 deletions.
There are no files selected for viewing
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
99 changes: 99 additions & 0 deletions
99
...n/java/org/eclipse/dirigible/components/data/management/config/DatabaseMetadataCache.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors | ||
* | ||
* All rights reserved. This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible | ||
* contributors SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.dirigible.components.data.management.config; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.eclipse.dirigible.commons.config.Configuration; | ||
|
||
import com.github.benmanes.caffeine.cache.Cache; | ||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
|
||
/** | ||
* The Class CaffeineDatabaseMetadataCache. | ||
*/ | ||
public class DatabaseMetadataCache { | ||
|
||
private static final String DIRIGIBLE_DATABASE_METADATA_CACHE_TIME_LIMIT_IN_MINUTES = | ||
"DIRIGIBLE_DATABASE_METADATA_CACHE_TIME_LIMIT_IN_MINUTES"; | ||
|
||
/** The cache. */ | ||
private Cache<String, String> cache; | ||
|
||
/** | ||
* Instantiates a new caffeine database metadata cache. | ||
*/ | ||
public DatabaseMetadataCache() { | ||
initCache(); | ||
} | ||
|
||
/** | ||
* Inits the cache. | ||
*/ | ||
private void initCache() { | ||
long timePolicy = Long.parseLong(Configuration.get(DIRIGIBLE_DATABASE_METADATA_CACHE_TIME_LIMIT_IN_MINUTES, "60")); | ||
cache = Caffeine.newBuilder() | ||
.expireAfterAccess(timePolicy, TimeUnit.MINUTES) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Gets the internal cache. | ||
* | ||
* @return the internal cache | ||
*/ | ||
public Cache<String, String> getInternalCache() { | ||
if (cache == null) { | ||
initCache(); | ||
} | ||
|
||
return cache; | ||
} | ||
|
||
/** | ||
* Gets the. | ||
* | ||
* @param path the path | ||
* @return the String | ||
*/ | ||
public String get(String path) { | ||
return cache.getIfPresent(path); | ||
} | ||
|
||
/** | ||
* Put. | ||
* | ||
* @param path the path | ||
* @param content the content | ||
*/ | ||
public void put(String path, String content) { | ||
if (content != null) { | ||
cache.put(path, content); | ||
} | ||
} | ||
|
||
/** | ||
* Removes the. | ||
* | ||
* @param path the path | ||
*/ | ||
public void remove(String path) { | ||
cache.invalidate(path); | ||
} | ||
|
||
/** | ||
* Clear. | ||
*/ | ||
public void clear() { | ||
cache.invalidateAll(); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
.../org/eclipse/dirigible/components/data/management/config/DatabaseMetadataCacheConfig.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors | ||
* | ||
* All rights reserved. This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible | ||
* contributors SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.dirigible.components.data.management.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class DatabaseMetadataCacheConfig { | ||
|
||
@Bean | ||
public DatabaseMetadataCache getDatabaseMetadataCache() { | ||
return new DatabaseMetadataCache(); | ||
} | ||
|
||
} |
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
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
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
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
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