c# - Cache Entity Framework data and track its changes? -


what want pretty simple conceptually can't figure out how best implement such thing.

in web application have services access repositories access ef interacts sql server database. of these instanced once per web request.

i want have layer between repositories , ef (or services , repositories?) statically keeps track of objects being pulled , pushed database.

the goal, assuming db-access accomplished through application, know fact unless repository access ef , commits change, object set didn't change.

an example be:

repository invokes method getallcarrots();

getallcarrots() performs query on sql server retrieving list<carrot>, if nothing else happens in between, prevent query being made on sql server each time (regardless of being on different web request, want able handle scenario)

now, if call buycarrot() adds carrot table, want invalidate static cache carrots, make getallcarrots(); require query database once again.

what resources on database caching?

you can use linqtocache this.

it allows use following code inside repository:

var querytags = t in ctx.tags select t; var tags = querytags.ascached("tags"); foreach (tag t in tags) {   ... } 

the idea use sqldependency notified when result of query changes. long result doesn't change can cache it.

linqtocache keeps track of queries , returns cached data when queried. when notification received sqlserver cache reset.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -