1

I would like to know if salesforce has any type of caching services?

Any type of service that would allow me to keep data across web requests and in memory ?

I did some research and did not find anything native to salesforce.

Like cache SOQL object results , so they don’t have to constantly be queried

I come from a java development environment. There are many caching solutions in Java

1) Object caching (keeps object in memory)

2) Query result caching (Keeps records in memory)

3) Application context (Keeps xml in memory)

My requirement is that I need configuration data. This data will have a small result set that will not change often but it will be used often.

So I would not like to query the database for it

Thanks

  • 5
    did you look at Custom Settings? These could do the trick – cropredy Dec 8 '14 at 20:20
  • @crop1645 is correct, the only caching allow is Custom Settings. If you are talking about something along the lines of using logic such as triggers, you can use static variables, though they only live the length of the transaction which is usually just a few milliseconds. Only catch if you are dealing with this is that during the "transaction" the CPU time limit is 10 seconds. If you reach that time, you will be rolled back and an error will be thrown. – Double A Dec 8 '14 at 20:48
  • +1 to custom settings - "All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database". Salesforce aims to keep no state at the server-side so you requests can be directed to any of many processors. – Keith C Dec 8 '14 at 21:15
  • @crop1645 Can you please post an answer about using Custom settings so it can be accepted as an answer. – Daniel Ballinger Dec 10 '14 at 0:07
2

For configuration settings, the best option is Custom Settings. From the doc:

All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database.

They can be manipulated using SOQL but in most cases, your Apex code will use them as if in-memory values - hence they act as omnipresent environment variables to your Apex transaction.

Hierarchical custom settings have an added advantage over list variables (especially at the org level) in that they can be used in validation rules and formula fields so they have utility beyond Apex.

As of V32 ..

Note that Custom Settings are not considered as org data when doing testmethods - so you'll need to mock their values where the underlying code being tested relies on the presence of the custom settings.

Note that you can't write validation rules or triggers on Custom Settings so if they can only take on specific values, you'll need to develop a VF page/controller with your own validation logic

Note also that the schema (metadata) of the custom settings can be deployed as any other SObject (including via changesets) but the actual values of the custom settings cannot be deployed without your own tools (e.g. changesets can't deploy custom setting values)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.