本文整理汇总了C#中System.Web.Caching.Cache.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.Insert方法的具体用法?C# Cache.Insert怎么用?C# Cache.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Caching.Cache
的用法示例。
在下文中一共展示了Cache.Insert方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FieldCacheFacade
public FieldCacheFacade()
{
string xmlFile = HttpContext.Current.Server.MapPath("~/schemamapping.xml");
CacheDependency xmlDependency = new CacheDependency(xmlFile);
Cache cache = new Cache();
cache.Insert("", null, xmlDependency);
}
示例2: GetMotos
public static IEnumerable<IPublishedContent> GetMotos(Cache motosCache)
{
var motos = motosCache["Motos"] as IEnumerable<IPublishedContent>;
if (motos == null)
{
var expiration = UmbracoHelper.TypedContentSingleAtXPath("/root/sysSiteSettings").GetPropertyValue<int>("cacheExpTimeMotos");
motos = UmbracoHelper.TypedContentAtXPath("/root/mainpage/Catalog//Bike");
motosCache.Insert("Motos", motos, null, DateTime.Now.AddHours(expiration), TimeSpan.Zero);
return motos;
}
return motos;
}
示例3: CreateInstance
public static Credential CreateInstance(string uid, Cache cache)
{
if (cache != null && !cache.Exists(uid))
{
Credential c = new Credential(uid, cache);
cache.Insert(uid, c, null, DateTime.MaxValue, DefaultDuration);
return c;
}
else
{
return cache[uid] as Credential;
}
}
示例4: Create
public static BritBoxingTwitterInfo Create(Cache cache, TwitterService service, bool useCache)
{
if (!useCache)
{
return new BritBoxingTwitterInfo(cache, service);
}
var info = cache["BritBoxingTwitterInfo"] as BritBoxingTwitterInfo;
if (info == null)
{
info = new BritBoxingTwitterInfo(cache, service);
cache.Insert("BritBoxingTwitterInfo", info);
}
return info;
}
示例5: AboutPresentationModel
public AboutPresentationModel()
{
Cache = HttpContext.Current.Cache;
if (Cache["key"] == null) //Initialize the datasource
{
List<Message> collection = new List<Message>();
//Some example data, for demo purpose
collection.Add(new Message { Name = "Peter Pan", MessageText = "Ping pong pan..." });
collection.Add(new Message { Name = "bart Simpson", MessageText = "The sky is blue, you are yellow" });
collection.Add(new Message { Name = "John Doe", MessageText = "Hi, I'am John" });
Cache.Insert("key", collection.AsEnumerable(), null,
System.Web.Caching.Cache.NoAbsoluteExpiration,
TimeSpan.FromDays(30));
}
}
示例6: Application_Start
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
_cache = Context.Cache;
BusinessLogic.Parameter.Parameter par = new BusinessLogic.Parameter.Parameter();
DataSet.DSParameter ds = par.GetParamerter();
System.TimeSpan span = new TimeSpan(0, 0, 2, 20, 0);
_cache.Insert("data", ds, null,
Cache.NoAbsoluteExpiration, span,
CacheItemPriority.Default,
new CacheItemRemovedCallback(RefreshData));
}
示例7: SaveImage
/// <summary>
/// SaveImage saves the bytes to a file and returns the file name. The cache is used to remember
/// the temporary file names and to timeout (and delete) the file.
/// </summary>
/// <param name="ba"></param>
/// <param name="c"></param>
/// <returns></returns>
static internal string SaveImage(string path, byte[] ba, Cache c)
{
Stream io = null;
string filename;
string url;
try
{
io = ImageHelper.GetIOStream(path, out filename, out url);
io.Write(ba, 0, ba.Length);
io.Close();
io = null;
ImageCallBack icb = new ImageCallBack();
CacheItemRemovedCallback onRemove = new CacheItemRemovedCallback(icb.RemovedCallback);
c.Insert(Path.GetFileNameWithoutExtension(filename),
filename, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero, CacheItemPriority.Normal, onRemove);
}
finally
{
if (io != null)
io.Close();
}
return url;
}
示例8: CacheJson
private static void CacheJson(Cache cache, string key, object value, string pathToFile)
{
CacheDependency dependency = new CacheDependency(pathToFile);
cache.Insert(key, value, dependency, Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration, CacheItemPriority.Normal, JsonItemRemovedCallback);
}
示例9: SaveCachedReport
internal static void SaveCachedReport(Report r, string file, Cache c)
{
if (!ReportHelper.DoCaching) // caching is disabled
return;
c.Insert(file, r.ReportDefinition, new CacheDependency(file));
return;
}
示例10: SetCache
public void SetCache(Cache cache,
string cacheKey,
object value,
int? tenantId = null,
int expirationSeconds = 0)
{
string key = GetTenantCacheKey(cacheKey, tenantId);
if (expirationSeconds == 0)
{
cache[key] = value;
}
else
{
DateTime cacheUntil = DateTime.UtcNow.AddSeconds(expirationSeconds);
cache.Insert(key,
value,
null,
cacheUntil,
System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Default,
null);
}
}
示例11: TryFindViewFromViewModel
protected string TryFindViewFromViewModel(Cache cache, object viewModel)
{
if (viewModel != null)
{
var viewModelType = viewModel.GetType();
var cacheKey = "ViewModelViewName_" + viewModelType.FullName;
var cachedValue = (string)cache.Get(cacheKey);
if (cachedValue != null)
{
return cachedValue != NoVirtualPathCacheValue ? cachedValue : null;
}
while (viewModelType != typeof(object))
{
var viewModelName = viewModelType.Name;
var namespacePart = viewModelType.Namespace.Substring("FODT.".Length);
var virtualPath = "~/" + namespacePart.Replace(".", "/") + "/" + viewModelName.Replace("ViewModel", "") + ".cshtml";
if (Exists(virtualPath) || VirtualPathProvider.FileExists(virtualPath))
{
cache.Insert(cacheKey, virtualPath, null /* dependencies */, Cache.NoAbsoluteExpiration, _defaultCacheTimeSpan);
return virtualPath;
}
viewModelType = viewModelType.BaseType;
}
// no view found
cache.Insert(cacheKey, NoVirtualPathCacheValue, null /* dependencies */, Cache.NoAbsoluteExpiration, _defaultCacheTimeSpan);
}
return null;
}
示例12: insertCache
public void insertCache(string key, object value , CacheDependency dependency)
{
Cache cache = new Cache();
cache.Insert(key, value, dependency);
}
示例13: ExecuteCacheReader
/// <summary>
///
/// </summary>
/// <param name="connectionString"></param>
/// <param name="cmdType"></param>
/// <param name="cmdText"></param>
/// <param name="commandParameters"></param>
/// <returns></returns>
//--------------------------------------------------------------------------------------------------------------
public static SqlDataReader ExecuteCacheReader(string connectionString, CommandType cmdType, string cmdText,string CacheKey, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(connectionString);
PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
SqlCacheDependency dependency = new SqlCacheDependency(cmd);
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
Cache cache = new Cache();
cache.Add(CacheKey, "", dependency, System.Web.Caching.Cache.NoAbsoluteExpiration,System.Web.Caching.Cache.NoSlidingExpiration,System.Web.Caching.CacheItemPriority.Default , null);
cache.Insert(CacheKey, rdr, dependency);
return (SqlDataReader)cache.Get(CacheKey) ;
// conn.Close();
// System.Web.HttpContext.Current.Response.Write(ex.Message.ToString());
}
示例14: GetMemberList
//.........这里部分代码省略.........
var tmp = AppCache.Get("ADUsersAndGroups" + ADDomain);
if (tmp != null)
{
return ((DataSet)tmp).Tables[0];
}
}
// create dataset
using (var ds = new DataSet())
{
using (var dt = new DataTable())
{
ds.Tables.Add(dt);
var dc = new DataColumn("DisplayName", typeof(string));
dt.Columns.Add(dc);
dc = new DataColumn("AccountName", typeof(string));
dt.Columns.Add(dc);
dc = new DataColumn("AccountType", typeof(string));
dt.Columns.Add(dc);
// add built in users first
dt.Rows.Add(new object[] { "Admins", "Admins", "group" });
dt.Rows.Add(new object[] { "All Users", "All Users", "group" });
dt.Rows.Add(new object[] { "Authenticated Users", "Authenticated Users", "group" });
dt.Rows.Add(new object[] { "Unauthenticated Users", "Unauthenticated Users", "group" });
// construct root entry
using (var rootEntry = GetDomainRoot(ADDomain))
{
if (ADDomain.Trim().ToLower().StartsWith("ldap://"))
{
var DomainName = GetNetbiosName(rootEntry);
// get users/groups
var mySearcher = new DirectorySearcher(rootEntry);
mySearcher.Filter = "(|(objectClass=group)(&(objectClass=user)(objectCategory=person)))";
mySearcher.PropertiesToLoad.Add("cn");
mySearcher.PropertiesToLoad.Add("objectClass");
mySearcher.PropertiesToLoad.Add("sAMAccountName");
SearchResultCollection mySearcherSearchResult;
try
{
mySearcherSearchResult = mySearcher.FindAll();
foreach (SearchResult resEnt in mySearcherSearchResult)
{
var entry = resEnt.GetDirectoryEntry();
var name = (string)entry.Properties["cn"][0];
var abbreviation = (string)entry.Properties["sAMAccountName"][0];
var accounttype = GetAccountType(entry);
dt.Rows.Add(
new object[] { name, DomainName + "\\" + abbreviation, accounttype.ToString() });
}
}
catch
{
throw new Exception("Could not get users/groups from domain '" + ADDomain + "'.");
}
}
else if (ADDomain.Trim().ToLower().StartsWith("winnt://"))
{
var DomainName = rootEntry.Name;
// Get the users
rootEntry.Children.SchemaFilter.Add("user");
foreach (DirectoryEntry user in rootEntry.Children)
{
var fullname = (string)user.Properties["FullName"][0];
var accountname = user.Name;
dt.Rows.Add(
new object[]
{
fullname, DomainName + "\\" + fullname, ADAccountType.user.ToString()
});
}
// Get the users
rootEntry.Children.SchemaFilter.Add("group");
foreach (DirectoryEntry user in rootEntry.Children)
{
var fullname = user.Name;
var accountname = user.Name;
dt.Rows.Add(
new object[]
{
fullname, DomainName + "\\" + fullname, ADAccountType.group.ToString()
});
}
}
}
// add dataset to the cache
AppCache.Insert("ADUsersAndGroups" + ADDomain, ds);
// return datatable
return dt;
}
}
}