disable caching for a specific function in doctrine - caching

I want to disable doctrine's default caching for a specific function(page), on all other pages, it should work as usual. Also I don't even want to clear the current caching inside that function. Just need that, no caching will be considered for that particular function call and its inside workflow.
Is there any easy way to achieve this? Thanks.

Rana, I believe you can use $query->useResultCache(false); to disable the cache for the page you want. Take a look at the documentation if needed.
Cheers,

You could use another entity manager for that specific page with caching turned off. As you didn't mention what kind of framework you use, I am unable to make any further assumptions.
According to the documentation (and personal experience) you shouldn't use doctrine without a cache:
Do not use Doctrine without a metadata and query cache! Doctrine is optimized for working with caches. The main parts in Doctrine that are optimized for caching are the metadata mapping information with the metadata cache and the DQL to SQL conversions with the query cache. These 2 caches require only an absolute minimum of memory yet they heavily improve the runtime performance of Doctrine. The recommended cache driver to use with Doctrine is APC. APC provides you with an opcode-cache (which is highly recommended anyway) and a very fast in-memory cache storage that you can use for the metadata and query caches as seen in the previous code snippet.
Would you mind sharing that specific need of yours to be able to provide you with a better answer/solution to your problem?

Related

Caching in Linq2DB

Does the Linq2DB ORM support query result caching - first level or second level? I noticed the namespace LinqToDB.Common.Internal.Cache, does it mean caching has to be built by the consuming application through a custom caching manager?
Well, linq2db is designed to work with queries not object management. Caching is a very specific case which introduces a lot of side effects. For example if you change some field and the cache contains such records - you have to invalidate the cache, otherwise the system will return obsolete data. Invalidating caches is the most difficult part here.
Anyway there are third party libraries which can do that for you:
LinqCache
Probably there are other libraries which can do similar things.

Write-Through and Read-Through caches

I was wondering which cache solutions support Write-Through or Read-Through caching.
I found out that Memcached only supports Cache-Aside caching and also that DAX supports Write-Through.
I was wondering about more caching engines such as Redis etc. and couldn't find the answer.
THX
Take a look at this project (https://github.com/RedisGears/rgsync) that uses RedisGears (https://oss.redislabs.com/redisgears/) to achieve Write-Behind and Write-Through on Redis.
Though it is not supporting Read-Through you can achieve it using RedisGears command reader (https://oss.redislabs.com/redisgears/readers.html#commandreader), just register a command that checks if the data exists on Redis, if its there then just return it. Otherwise, fetch it from wherever you want, save it on Redis, and return it.

GraphQL caching mechanism

I want to use GraphQL to access data from different data sources (CSV, SQL Server, Web Server) . I want to know if caching mechanism is supported, so that when the connection is lost the data is still available? I see the data loader which is data batching to increase the performance of the query, but I do not know how data loader can do caching?
Thanks.
There's no built-in support, but you need to remember that graphql-js (which I assume you're using) isn't a framework, it's just a library. You'd implement caching exactly the same as you'd do it with anything else - by surrounding your data-fetching functions with caching get/set behaviour.
I don't use caching very heavily with graphql-js, but if you've ever implemented caching before, it's exactly the same principle.

Doctrine 2 Caching Workflow

I am new to caching
What should I cache
eg. Do I cache user info? eg. since they are frequently used throughout the application (like in the header saying "welcome {username}")?
But most things should be used quite frequently anyways? eg. Users have projects. These projects don't belong to everyone, but they will be frequently used by specific users do I cache them too? Won't I be caching nearly everything then?
Also regarding CRUD, with doctrine queries, I can just use $query->useResultCache(true) but what happens when I update/delete an entity? I need to somehow update my cache too? how?
The basic principle of caching is to hold frequently used data that doesnt change often in memory to reduce database work.
Its more convenient to use the php session variables to hold basic things like username.
In case of projects, if they dont change often, and retrieved by users frequently, it would be a good idea to cache them. How long a project info stays cached depends on the change frequency.
Also note that if the info you present to users is vital or time important, you should use caching cautiously.
Check this reference page for basic information on caching http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html#cache-related-api
Or check http://www.doctrine-project.org/docs/orm/2.0/en/reference/caching.html for detailed explanation.

Best way to cache persistent data (e.g. code books) in Spring?

I have a series of code books in my database, and I am using plain JDBC calls to fetch them and store them in a collection. I would like to put these in some kind of a cache at application startup time in order to save time later.
I don't need any fancy stuff like automatic object invalidation, TTL etc - the code books change rarely, so I'll trigger the update myself and just reload the whole cache when the need arises.
The project where I need this uses Spring, and this is my first project using it. Is there a standard/elegant way to do this in Spring?
Thanks.
Check out Spring-cache.
Supports EHCache, OSCache and a memory cache, but allows pluggable cache providers too.

Resources