required to show a data of an id from an csv file from dam | Community
Skip to main content
Level 2
January 30, 2025
Solved

required to show a data of an id from an csv file from dam

  • January 30, 2025
  • 5 replies
  • 850 views

For a requirement on which data needs to be displyed from the csv file (this may be updated at times) from dam folder on searching of ID from Which is having a14k records. Triggering a servlet on search and putting records into a Map and displaying it by below idMap.containsKey(id) and giving the response back. As if the request are getting more the server is getting high cpu. Any solution can be applied in this scenario. 

Best answer by chaudharynick

Hi @sudeepkonjeti 

 

there are three ways that you can use:

 

  1. Resource based servlet with a selector - having id as a selector will have a separate cache for individual requests if the data is not getting updated runtime. you can set the cache ttl accordingly to have the updated content.
  2. Memory based cache - Guava Cache(https://www.baeldung.com/guava-cache) - It's a great feature that you can use to have memory-based cache with a lot of customizations.
  3. ACS Commons HTTP Cache (https://adobe-consulting-services.github.io/acs-aem-commons/features/http-cache/index.html) - this is similar to Guava cache but instead of storing some particular java object, it stores the complete request and you can define the TTL for this.

5 replies

anupampat
Community Advisor
Community Advisor
January 30, 2025

Hi @sudeepkonjeti ,

Is the csv file stored in AEM DAM and has around 14k rows, on which you are iterating to fetch a certain ID ?

Regards,

Anupam Patra

Level 2
January 30, 2025

Hi @anupampat  yes its is dam folder. 

Shiv_Prakash_Patel
Community Advisor
Community Advisor
January 30, 2025

Hi @sudeepkonjeti ,

As the number of requests increases, high CPU usage occurs due to repeated file parsing and object creation. You can follow the approach below to optimize access, improve scalability, and ensure fast responses.

1. Use In-Memory Cache (Guava Cache)

  • Store CSV data in memory and fetch IDs efficiently.
  • Avoids repeated file reading on each request.

2. Implement Read-Write Lock

  • Prevents multiple concurrent cache updates.

3. Use AEM Sling Scheduler for Cache Refresh

  • Auto-refresh cache every 30 minutes in the background.

Regards,

Shiv Prakash
Level 2
February 19, 2025

HI @shiv_prakash_patel  thanks for your suggestion.  But I can see the users are unique so every time new ID may be fetched in that case how much feasible this approach.  

AmitVishwakarma
Community Advisor
Community Advisor
February 1, 2025

To optimize performance and reduce CPU usage:

Use In-Memory Cache (e.g., Guava Cache) to store parsed CSV data, avoiding repeated file parsing on each request.
Implement Read-Write Lock to prevent concurrent cache updates.
Use AEM Sling Scheduler to automatically refresh the cache every 30 minutes or as needed.

This approach improves scalability and ensures faster responses.

chaudharynick
chaudharynickAccepted solution
Level 4
February 3, 2025

Hi @sudeepkonjeti 

 

there are three ways that you can use:

 

  1. Resource based servlet with a selector - having id as a selector will have a separate cache for individual requests if the data is not getting updated runtime. you can set the cache ttl accordingly to have the updated content.
  2. Memory based cache - Guava Cache(https://www.baeldung.com/guava-cache) - It's a great feature that you can use to have memory-based cache with a lot of customizations.
  3. ACS Commons HTTP Cache (https://adobe-consulting-services.github.io/acs-aem-commons/features/http-cache/index.html) - this is similar to Guava cache but instead of storing some particular java object, it stores the complete request and you can define the TTL for this.
kautuk_sahni
Community Manager
Community Manager
February 18, 2025

@sudeepkonjeti Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!

Kautuk Sahni