Compiled cache request?

Most of my application uses the requested queries to retrieve data. In these queries, I often refer to the current user. I notice that if user, B, logs in after another user, A, then user B will see the information of user A.

I have queries similar to all this through the app

public static Func<DataContext, MyRecord> CurrentUserRecords =
            CompiledQuery.Compile<DataContext, MyRecord>(
                (DataContext db) =>
                    (from r in db.MyRecords
                     where
                        r.User == User.Current 
                     select r).SingleOrDefault());

User.Current is a static property that changes depending on who is logged in.

public static User Current 
{
    get { return MyBase<User>.Get((int)(HttpContext.Current.Session["CurrentUserID"] ?? 0)); }
}

User A, User A. , User.Current A. , B, - User A, , User.Current B.

Profiler SQL Server , TSQL, A, .

, :

- ?

, , ?

" " ASP.net?

!

+3
1

. .Compile(). :

public static Func<DataContext, string, MyRecord> UserRecordByParam =
  CompiledQuery.Compile<DataContext, string, MyRecord>
(
  (DataContext db, string UserName) =>
   db.MyRecords.Where( r => r.User == UserName ).SingleOrDefault()
);

public static Func<DataContext, MyRecord> CurrentUserRecord =
  (DataContext db) => UserRecordByParam(db, User.Current);
+2

Source: https://habr.com/ru/post/1710624/


All Articles