// Retuns an item from the cache corresponding to the GUID key passed to the method public static Invoices GetItem(string guid) { // Cleans cache cache.RemoveOld(cacheDuration); cache.RemoveOldest(maxCacheSize); if (cache.ContainsKey(guid)) { return(cache[guid]); } else { return(new Item()); } }
private void FetchItems(bool bBypassItems) { List <Document> oDocuments; List <Document> oSearchDocuments; Field oIdField; string sItemId; bool bPermitted = true; //create a list of result objects oDocuments = new List <Document>(); //do we have any query attributes? if (oQueries.Count > 0) { if (oQueries.ContainsKey(Constants.Investments.Indexes.Fields.Title)) { oQuery = oQueries[Constants.Investments.Indexes.Fields.Title]; oQueries.Remove(Constants.Investments.Indexes.Fields.Title); } else { oQuery = SearchHelper.CreateBooleanQuery(Occur.MUST, oQueries.Values.ToArray()); } if (oDefaultQuery != null) { oQuery = SearchHelper.CreateBooleanQuery(Occur.MUST, oQuery, oDefaultQuery); } //get documents from search oSearchDocuments = SearchHelper.SearchLuceneIndex(oQuery, Constants.Investments.Indexes.InvestmentsResearchIndex); } else { //get all documents oSearchDocuments = SearchHelper.SearchLuceneIndex(ALL_ITEMS_QUERY, Constants.Investments.Indexes.InvestmentsResearchIndex); } if (!bBypassItems) { //do we have documents? if (oSearchDocuments != null) { //loop over the documents foreach (Document oDocument in oSearchDocuments) { //get the id field if ((oIdField = oDocument.GetField(Genworth.SitecoreExt.Constants.Investments.Indexes.Fields.Id)) != null && !string.IsNullOrEmpty(sItemId = oIdField.StringValue)) { //lock on the item cache lock (oItemCache) { //is this item in the item cache already? if (oItemCache.ContainsKey(sItemId)) { //get the item bPermitted = oItemCache[sItemId]; } else { //get the item from Sitecore bPermitted = ContextExtension.CurrentDatabase.GetItem(ItemPointer.Parse(sItemId).ItemID) != null; //add to the list oItemCache.Add(sItemId, bPermitted); } } //we only want to use this item if it is non-null if (bPermitted) { //add teh document to hte list oDocuments.Add(oDocument); } } } } //store the results oResultDocuments = oDocuments.ToArray(); } else { oResultDocuments = oSearchDocuments.ToArray(); } //turn off dirty flag bIsDirty = false; }
private void FetchItems(bool bBypassItems) { List <Document> oDocuments; List <Document> oSearchDocuments; Field oIdField; string sItemId; bool bPermitted; //create a list of result objects oDocuments = new List <Document>(); //get documents from search oSearchDocuments = SearchHelper.SearchLuceneIndex(oQuery, Constants.Investments.Indexes.InvestmentManagerStrategiesIndex); if (!bBypassItems) { //do we have documents? if (oSearchDocuments != null) { //loop over the documents foreach (Document oDocument in oSearchDocuments) { //get the id field if ((oIdField = oDocument.GetField(Genworth.SitecoreExt.Constants.Investments.Indexes.Fields.Id)) != null && !string.IsNullOrEmpty(sItemId = oIdField.StringValue)) { //lock on the item cache lock (oItemCache) { //is this item in the item cache already? if (oItemCache.ContainsKey(sItemId)) { //get the item bPermitted = oItemCache[sItemId]; } else { //get the item from Sitecore bPermitted = ContextExtension.CurrentDatabase.GetItem(ItemPointer.Parse(sItemId).ItemID) != null; //add to the list oItemCache.Add(sItemId, bPermitted); } } //we only want to use this item if it is non-null if (bPermitted) { //add teh document to hte list oDocuments.Add(oDocument); } } } } //store the results oResultDocuments = oDocuments.ToArray(); //turn off dirty flag bIsDirty = false; } else { oResultDocuments = oSearchDocuments.ToArray(); } }