FYI Your code is not proper as it throwing error
1) You have not declared the cacheItem before if condition so it throws build error.
2) Your last line where you are inserting the cacheItem in same cache object it also throws error as cacheitem is null.
So be sure you have coded correctly.
Check the below example if the cache is null or if cache is exist but stored value different for the same cache then again insert new input value to the cache.
C#
// your input parameter value as string based on your logic from where you are passing
string yourcatchvalue = "123";
object cacheItem = HttpContext.Current.Cache["mycache"] as string;
if (cacheItem == null)
{
HttpContext.Current.Cache.Insert("mycache", yourcatchvalue, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero);
}
else if (cacheItem != yourcatchvalue)
{
HttpContext.Current.Cache.Insert("mycache", yourcatchvalue, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero);
}