Modify An Object From Cache And It Changes The Cached Value
May 8, 2010
I'm having an issue when using the Asp.Net Cache functionality. I add an object to the Cache then at another time I get that object from the Cache, modify one of it's properties then save the changes to the database.
But, the next time I get the object from Cache it contains the changed values. So, when I modify the object it modifies the version which is contained in cache even though I haven't updated it in the Cache specifically. Does anyone know how I can get an object from the Cache which doesn't reference the cached version?i.e.
Step 1:
Item item = new Item();
item.Title = "Test";
Cache.Insert("Test", item, null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration);
Step 2:
Item item = (Item)Cache.Get("test");
item.Title = "Test 1";
Step 3:
Item item = (Item)Cache.Get("test");
if(item.Title == "Test 1"){
Response.Write("Object has been changed in the Cache.");
}
I realise that with the above example it would make sense that any changes to the item get reflected in cache but my situation is a bit more complicated and I definitely don't want this to happen.
View 2 Replies
Similar Messages:
Dec 17, 2010
I read few xml files from a location and cache them using Http context cache. Anytime the xml files changes i have to do a IISReset to view the latest changes.
I use this
System.Web.HttpContext.Current.Cache
I have to use the caching as i don't want to read all the xml files all the time. i read it once and caches them for a day. They get reset whenever apppool recyles or anyone manualy do a IISReset.
Is there anyway in asp.net to invalidate the cache if someones changes the xml file.
View 1 Replies
Oct 25, 2013
when i first run my applcation some time its showing the data from cache.i want to avoid it in first time .
i want to cache my all images/css/js file what is the efficient way to do it.
i have lot of images folder /js /css files.
View 1 Replies
Jan 17, 2010
U are caching a list of items, then Add or update or delete method called. Approach 1)
A- Do the data change at the database. If success do B, C
B- Remove the entire list from the Cache.
C- Re-Cache the list on first read.
Approach 2)
A- Do the data change at the database, If success do B
B- Do the same change at the cached items, and save more time.
Approach(2) probably will cause nasty difficult to spot bugs, because the data come from BLL and placed directly into cache, One can't assume no bugs will happen at the sproc, I am not worry about database runtime errors, runtime errors will show up, but I am worry about invalid data, or miss calculation. Can I proceed with approach (2) with caution? Is there a "best practice" principle which suggest not doing approach(2)?
View 2 Replies
Mar 29, 2010
Is it correct to implement my caching object like this in my controller :
[code]....
And I Use it like this :
[code]....
View 1 Replies
Feb 24, 2010
We are using HttpRuntime.Cache API in an ASP.NET to cache data retrieved from a database.
For this particular application, our database queries feature a LOT of parameters, so our cache keys look something like this:
table=table1;param1=somevalue1;param2=somevalue2;param3=somevalue3;param4=somevalue4;param5=somevalue5;param6=somevalue6... etc...
we have so many parameters that the cache key is several hundred characters long. is there a limit to the length of these cache keys? Internally, it is using a dictionary, so theoretically the lookup time should be constant. However, I wonder if we have potential to run into some performance/memory problem.
View 1 Replies
Nov 2, 2010
I need to enable caching in my asp.net application, but I do not want to use the webserver's memory for holding cache objects. If I add the page directive for output caching will the page be stored in the asp.net cache object?
View 2 Replies
Jun 22, 2010
I have a WCF 3.5 service with JSON and a aspx page consuming it by using ASP.NET Ajax Library
I was able to call service succesfully.In the aspx page I wrote my Java code directly and then I wanted to modify my JS function but it is always picking the old JS function code
I even restarted the machine no change, looked up on the internet, msdn and I have Default pool with Integration mode
code bellow
<asp:ScriptManager
ID="ScriptManager1"
runat="server" [code]....
View 2 Replies
Jun 6, 2010
In an ASP.NET 3.5 VB web app, I successfully manage to cache an object containing several personal details such as name, address, etc. One of the items is CreditNum which I'd like to change in the cache on the fly. Is there a way to access this directly in the cache or do I have to destroy and rebuild the whole object just to change the value of objMemberDetails.CreditNum?The cache is set using:
Public Shared Sub CacheSet(ByVal key As String, ByVal value As Object)
Dim userID As String = HttpContext.Current.User.Identity.Name
HttpContext.Current.Cache(key & "_" & userID) = value
End Sub
View 1 Replies
Mar 10, 2010
I have a website that i did some time ago now they request some new features and i did some changes in some javascript files, but when i publish the clients that use the IE have problems with cache so in they browser they have old version of javascript. How can i clear the client cache so when they visit website they use latest javascript files that i modify.
View 1 Replies
Jul 2, 2010
I found some code on the web and it threw me off. Look at the code below. You will notice only when the Hits == 1, does the cache get added. After that, the cache object isn't updated. It begs the question, does the object when updated, update the cache as well automatically? The answer here would make me remove some code in some of my classes.
public static bool IsValid( ActionTypeEnum actionType )
{
HttpContext context = HttpContext.Current;
if( context.Request.Browser.Crawler ) return false;
string key = actionType.ToString() + context.Request.UserHostAddress;
var hit = (HitInfo)(context.Cache[key] ?? new HitInfo());
if( hit.Hits > (int)actionType ) return false;
else hit.Hits ++;
if( hit.Hits == 1 )
context.Cache.Add(key, hit, null, DateTime.Now.AddMinutes(DURATION),
System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Normal, null);
return true;
}
I would only guess that I would need to add the lines after the if statement:
if( hit.Hits == 1 )
context.Cache.Add(key, hit, null, DateTime.Now.AddMinutes(10),
System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Normal, null);
else if (hit.Hits > 1)
{context.Cache.Remove(key);
context.Cache.Add(key, hit, null, DateTime.Now.AddMinutes(10),
System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Normal, null);
}
Found the code at the bottom of the page here: http://www.codeproject.com/KB/aspnet/10ASPNetPerformance.aspx?msg=2809164
View 1 Replies
May 26, 2010
I am caching a file in ttpContext.Current.Application object. Now when I change the values in file, it does not get reflected in the application (I am reading the values from the file for app version).
Even after restarting the app pool and the website in IIS, the changes does not reflect. I dont want to restart IIS.
View 1 Replies
Sep 2, 2010
Backgroud: I'm using NHibernate for my model layer, and I have a HTTP module taking care of instantiating the session at the beginning of each request and cleaning it up at the end of each request (i.e. Session Per Request). In this case, I have two object types:
ParentItem - an object with a bunch of properties and a collection of ChildItems. ChildItem - an object with properties including a DateTime (EffectiveDate) and an unenforced FK pointing to a completely different database. The ChildItem class contains a reference back to the parent as well (many-to-one) While the ParentItem has multiple ChildItems in its collection, I'm only generally interested in the latest ChildItem in the collection.
Desire: Want a databound control (GridView or ListView, I don't care which) that allows me to Add/Edit/Delete ParentItems from my datasource. I also want to have the ability to set a new "latest" ChildItem as part of the edit/update.
Issue: I can't seem to access the underlying DataItem from the GridView/ListView in the OnItemUpdating handler (which isn't unexpected, since the data is now in the viewstate). What I thought I could do would be to load a ParentItem from my session using the ID from the databound control, create a new ChildItem, add it to the ParentItem, and then save the ParentItem. Since NHibernate caches the data, the load should give me a copy from cache (no roundtrip to the DB) and I'd either be doing this before the ParentItem was saved back (thus no changes committed to ParentItem, just to ChildItem) or after (thus the cached version is still the same, and my new object will match the updated version). What I get when I do this (for ParentItemID=1):
a different object with the same identifier value was already associated with the session: 1, of entity:
NameSpace.ParentItem
on the line:
Session.SaveOrUpdate(parentItemInstance);
View 1 Replies
Jun 18, 2010
I'm using Dynamic Data and LINQ to SQL for some admin pages on a .NET 3.5 web app. All my admin tables have a CreatedBy, CreatedDate, UpdatedBy, and UpdatedDate.I'm looking for a way to inject the setting of these properties before the objects are inserted and updated.
I've seen an object_inserting hook if you have a linq to sql datasource in the web form, but I'm using dynamic data...is there an easy way to generically set that? And I've also looked at modifying each of the partial classes for my admin objects, but the closest hook I see is to implement the OnValidate method with the Insert action.
View 1 Replies
Jan 11, 2011
Can I synclock effectively on an object stored in the cache?Like:
SyncLock System.Web.HttpContext.Current.Cache("Some Object")
'do some stuff that is threadsafe on this cached object'
End SyncLock
Will this stop another thread from modifying that cached object?
View 1 Replies
Dec 8, 2010
I cannot add a new column in existing table.
I have a two tables ['ev_event_how' & 'ev_events_event_how'] has relationship between these table.
Ex:
Table: 'ev_event_how'
UID - Event[PK]
Ex:
Table: 'ev_events_event_how'
UID - Event[FK] - Desc
I want to add a one more column[IsDelete] in both table. But Sql server is not allowing to add the new column, Showing various errors like
1.cannot add a new column-Unable to modify table.Invalid object name 'MSED_Logs.DatabaseLog'
2.TITLE: Microsoft SQL Server Management Studio
User canceled out of save dialog (MS Visual Database Tools)
How can I make it add a new column in existing table?
View 4 Replies
Jan 13, 2011
Is there any way to return object from Session when Select is called on ObjectDataSource? Specifically, I have Products object and saved in Session. Now on another page I have ObjectDataSource which will call same bussiness object method to get Products object. Here I want to hook up any event like Selecting and I would like to return Products object from Session to Select method of ObjectDataSource.
View 1 Replies
May 31, 2010
I've been developing an application using asp.net MVC, and I have some configurations that influences in process of render a view. For example, a user can choose (in an configuration of system) if a field should appear for a management of records in an area of the system. So, I have an class called AppConfiguration has some properties to represent this configurations.
I guess I need to cache an object of AppConfiguration, and make a ViewModel base class and inherits from my viewmodel, for example:
public class BaseViewModel {
public AppConfiguration Config { get; set; }
}
public class DocumentViewModel : BaseViewModel {
public Document Document { get; set; }
}
and make typed views using "DocumentViewModel" to check the properties if this kind of document is able to render or not ? is it works ? Or is there any other better way to do something like this ?
View 1 Replies
Sep 24, 2010
I am working with asp.net mvc and i am trying to get acces to a object that is in the cache.In the Application_Start() of Global.asax.cs i create and store an object in the cache like this:
Translator translator = new Translator();
HttpContext.Current.Cache.Insert("Translator", translator, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration);
Translator holds a dictionary with translations.Now i want acces to this object from the cache to use functions and get values from the dictionary.I know i can acces it like this HttpContext.Current.Cache.Get("Translator") or Cache.Get("Translator") in the views But how can i use the functions of the object ? The meaning of the cache is to have a object that is accesable througout the webapp right ?
Do i have to make an object and asses the value of the Cache.Get("Translator") to it, so i can use the functions or is there another solution?
View 3 Replies
Aug 4, 2010
I thought I would put those settings into Cache and then invalidate them if the web.Config file changes. Reading some articles make it seem that this is completely unnecessary.
View 1 Replies
Jul 26, 2010
i have simple form which consists of 2 labels and 2 buttons, the first label will display the current time and second label will display the cached time for 2 mins which is absolute..
no w when i click on first button only current time have to get update,, and when i click on second button both current time cached time have to be updated even though the cached time of 2 mins not elapsed also.
View 4 Replies
Aug 7, 2010
This source what i have used to create cache object.Also i have checked if "AppCache_Caption" cache object is available or not.
[Code]....
Right now i have checked and created my login page page_load event.It will create cache object every time me access the login page.What are the conditions wrong my source?My expectation, cache object creates only one time.It will not create everytime.
View 4 Replies
Sep 1, 2010
In an ASP.NET web app written in VB.NET, I need to load and store a large read-only hash table that is frequently accessed by the application. It only needs to be loaded once on application start, is never updated and can be accessed by any session at any time.
If I load the hash table into a private member in a (global) module, a lookup to it takes one 20th of the time compared to storing the hash table in the Application or Cache object. Is there any reason why I should not do this, or should Application or Cache always be used to store in-memory objects in an ASP.NET web application?
View 1 Replies
Aug 22, 2010
I need to cache System.Collection.Generic.List object with expiration time
var Root = from feed in feedhotel.Descendants(ota + "HotelContent")
where (feed.Attribute("HotelCode") != null)
select new xmlhotel()
{
};
return Root.ToList();
Is it possible to cache Root.ToList() for some time....
View 1 Replies
Feb 25, 2011
We have a wfc layer that wraps the business classes and database access and use a client that lives on the database layer. Amongst our group we are attempting to form standards. Some want to have the client call the web method and pass the page they are requesting and the page size. Pass that to the database and then page in SQL Server use RowNum.Some want to cache the full list of objects in http cache on the service tier and page in memory. They concern here is memory use on the server.
Which would be best for a medium number of users with potentially large number of records to manage (say 30K) Is it better to cache them all in memory and work from there or page at the database as the application scales?
View 1 Replies