Search in sources :

Example 1 with ConfigStoreBasedTemplateCacheKey

use of org.wso2.carbon.identity.template.mgt.cache.ConfigStoreBasedTemplateCacheKey in project carbon-identity-framework by wso2.

the class CacheBackedConfigStoreBasedTemplateHandler method clearTemplateCache.

/**
 * Clearing cache entries related to the template.
 *
 * @param templateId Template id.
 */
private void clearTemplateCache(String templateId) throws TemplateManagementException {
    Template template = this.getTemplateById(templateId);
    if (template != null) {
        if (log.isDebugEnabled()) {
            log.debug("Removing entry for Template with id " + templateId + " from cache.");
        }
        ConfigStoreBasedTemplateCacheKey cacheKey = new ConfigStoreBasedTemplateCacheKey(templateId);
        configStoreBasedTemplateCache.clearCacheEntry(cacheKey, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Entry for Template with id " + templateId + " not found in cache or DB");
        }
    }
}
Also used : ConfigStoreBasedTemplateCacheKey(org.wso2.carbon.identity.template.mgt.cache.ConfigStoreBasedTemplateCacheKey) Template(org.wso2.carbon.identity.template.mgt.model.Template)

Example 2 with ConfigStoreBasedTemplateCacheKey

use of org.wso2.carbon.identity.template.mgt.cache.ConfigStoreBasedTemplateCacheKey in project carbon-identity-framework by wso2.

the class CacheBackedConfigStoreBasedTemplateHandler method getTemplateById.

/**
 * Get the template for the given id from config store.
 *
 * @param templateId Template id.
 * @return Template for the given id.
 * @throws TemplateManagementException Template Management Exception.
 */
public Template getTemplateById(String templateId) throws TemplateManagementException {
    ConfigStoreBasedTemplateCacheKey cacheKey = new ConfigStoreBasedTemplateCacheKey(templateId);
    ConfigStoreBasedTemplateCacheEntry entry = configStoreBasedTemplateCache.getValueFromCache(cacheKey, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
    if (entry != null) {
        if (log.isDebugEnabled()) {
            log.debug("Cache entry found for Template with id " + templateId);
        }
        Template template = entry.getTemplate();
        return template;
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cache entry not found for Template with id " + templateId + ". Fetching entry from DB");
        }
    }
    Template template = configStoreBasedTemplateHandler.getTemplateById(templateId);
    if (template != null) {
        if (log.isDebugEnabled()) {
            log.debug("Entry fetched from Config store for Template " + templateId + ". Updating cache");
        }
        configStoreBasedTemplateCache.addToCache(cacheKey, new ConfigStoreBasedTemplateCacheEntry(template), PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Entry for Template with id " + templateId + " not found in cache or config store");
        }
    }
    return template;
}
Also used : ConfigStoreBasedTemplateCacheEntry(org.wso2.carbon.identity.template.mgt.cache.ConfigStoreBasedTemplateCacheEntry) ConfigStoreBasedTemplateCacheKey(org.wso2.carbon.identity.template.mgt.cache.ConfigStoreBasedTemplateCacheKey) Template(org.wso2.carbon.identity.template.mgt.model.Template)

Aggregations

ConfigStoreBasedTemplateCacheKey (org.wso2.carbon.identity.template.mgt.cache.ConfigStoreBasedTemplateCacheKey)2 Template (org.wso2.carbon.identity.template.mgt.model.Template)2 ConfigStoreBasedTemplateCacheEntry (org.wso2.carbon.identity.template.mgt.cache.ConfigStoreBasedTemplateCacheEntry)1