Skip to content
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

Automated Cache initialisation #11451

Open
PuszekSE opened this issue Jul 23, 2024 · 0 comments
Open

Automated Cache initialisation #11451

PuszekSE opened this issue Jul 23, 2024 · 0 comments

Comments

@PuszekSE
Copy link

PuszekSE commented Jul 23, 2024

I've been looking into using Ignite as an automated Caching layer on top of existing database table and I've just realised that it requires you to MANUALLY call LoadData after startup.

The setup I'm looking into is pure helm/k8s deployment, so all the cache configurations, query entities, connections, etc. already exist and are operational, but it seems like it's impossible to configure it to automatically scrape the data from the datasource.

From my understanding Ignite already operates on top of Spring, so it should be possible to include some basic cache initialisation capabilities.

Very simple (autogenerated) piece of code that I would consider, is something like this?...
(Obviously it requires modifications inside related libraries, to actually properly pass the rest of configuration
(In my case, mainly cacheStoreFactory configs, that already provide the information on how to actually load the cache)

@Configuration
@EnableScheduling
public class CustomCacheConfiguration<K, V> extends CacheConfiguration<K, V> {

    @IgniteInstanceResource
    private Ignite ignite;

    private String cronExpression;
    private boolean initializeOnCreate;

    public CustomCacheConfiguration(String name, String cronExpression, boolean initializeOnCreate) {
        super(name);
        this.cronExpression = cronExpression;
        this.initializeOnCreate = initializeOnCreate;
    }

    @PostConstruct
    public void postConstruct() {
        if (initializeOnCreate) {
            initializeCache();
        }
    }

    @Scheduled(cron = "#{@customCacheConfiguration.cronExpression}")
    public void scheduledInitializeCache() {
        initializeCache();
    }

    public void initializeCache() {
        IgniteCache<K, V> cache = ignite.getOrCreateCache(this);
        cache.loadCache(null);
    }
}

initializeCache is also a method that could be easily exposed as part of RestAPI.

I'm not sure whether it's desired feature, but I believe it's something that would greatly increase the usability of Ignite in somewhat basic scenarios, especially with current shift into full k8s-based environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant