private Long retrieveRecordIdFromCache(UUID tagId) { final CacheController<Object, Object> cache = controlCacheDispatcher.getCacheController(CacheType.RECORD_ID); Object result = null; if (cache != null) { result = cache.get(tagId.toString(), ObjectType.TAG); } return (Long) result; }
public static String getCachedValue(String jsonCacheName, String ckey) { Cache cache = CacheController.getCache(); Map<String, String> thisCache = (HashMap<String, String>) cache.get(jsonCacheName); if (thisCache == null) { return null; } return thisCache.get(ckey); }
public static void updateCacheValue(String jsonCacheName, String ckey, String results) { Cache cache = CacheController.getCache(); Map<String, String> thisCache = (HashMap<String, String>) cache.get(jsonCacheName); if (thisCache == null) { thisCache = new HashMap<String, String>(); } thisCache.put(ckey, results); cache.put(jsonCacheName, thisCache); }
@Override protected void initApplicationContext() { super.initApplicationContext(); if (jsonCacheName != null) { Cache cache = CacheController.getCache(); Map<String, String> thisCache = new HashMap<String, String>(); cache.put(jsonCacheName, thisCache); logcache.log(Level.FINE, "Recreating cache: {0}", jsonCacheName); } }
public static void invalidateCacheValue(String jsonCacheName, String ckey) { Cache cache = CacheController.getCache(); Map<String, String> thisCache = (HashMap<String, String>) cache.get(jsonCacheName); if (thisCache != null) { thisCache.remove(ckey); } else { thisCache = new HashMap<String, String>(); } cache.put(jsonCacheName, thisCache); }
public void clearAll() { for (final CacheController<Object, Object> cacheController : caches.values()) { cacheController.removeAll(); } }
/** * This method simulates a call to a page so all castor caches fills up before we throw the old * page cache. * * @param db * @param siteNodeId * @param languageId * @param contentId */ public void recache(DatabaseWrapper dbWrapper, Integer siteNodeId) throws SystemException, Exception { logger.info("recache starting.."); HttpHelper helper = new HttpHelper(); String recacheUrl = CmsPropertyHandler.getRecacheUrl() + "?siteNodeId=" + siteNodeId + "&refresh=true&isRecacheCall=true"; String response = helper.getUrlContent(recacheUrl, 30000); String recacheBaseUrl = CmsPropertyHandler.getRecacheUrl().replaceAll("/ViewPage.action", ""); String pathsToRecacheOnPublishing = CmsPropertyHandler.getPathsToRecacheOnPublishing(); if (pathsToRecacheOnPublishing.indexOf("pathsToRecacheOnPublishing") == -1) { String[] pathsToRecacheOnPublishingArray = pathsToRecacheOnPublishing.split(","); for (int i = 0; i < pathsToRecacheOnPublishingArray.length; i++) { recacheUrl = recacheBaseUrl + pathsToRecacheOnPublishingArray[i] + "?refresh=true&isRecacheCall=true"; logger.info("calling recacheUrl:" + recacheUrl); } } LanguageVO masterLanguageVO = LanguageDeliveryController.getLanguageDeliveryController() .getMasterLanguageForSiteNode(dbWrapper.getDatabase(), siteNodeId); if (masterLanguageVO == null) throw new SystemException("There was no master language for the siteNode " + siteNodeId); Integer languageId = masterLanguageVO.getLanguageId(); if (languageId == null) languageId = masterLanguageVO.getLanguageId(); Integer contentId = new Integer(-1); Principal principal = (Principal) CacheController.getCachedObject("userCache", "anonymous"); if (principal == null) { Map arguments = new HashMap(); arguments.put("j_username", CmsPropertyHandler.getAnonymousUser()); arguments.put("j_password", CmsPropertyHandler.getAnonymousPassword()); principal = ExtranetController.getController() .getAuthenticatedPrincipal(dbWrapper.getDatabase(), arguments); if (principal != null) CacheController.cacheObject("userCache", "anonymous", principal); } FakeHttpSession fakeHttpServletSession = new FakeHttpSession(); FakeHttpServletResponse fakeHttpServletResponse = new FakeHttpServletResponse(); FakeHttpServletRequest fakeHttpServletRequest = new FakeHttpServletRequest(); fakeHttpServletRequest.setParameter("siteNodeId", "" + siteNodeId); fakeHttpServletRequest.setParameter("languageId", "" + languageId); fakeHttpServletRequest.setParameter("contentId", "" + contentId); fakeHttpServletRequest.setRequestURI("ViewPage.action"); fakeHttpServletRequest.setAttribute("siteNodeId", "" + siteNodeId); fakeHttpServletRequest.setAttribute("languageId", "" + languageId); fakeHttpServletRequest.setAttribute("contentId", "" + contentId); fakeHttpServletRequest.setServletContext(DeliverContextListener.getServletContext()); BrowserBean browserBean = new BrowserBean(); // this.browserBean.setRequest(getRequest()); NodeDeliveryController nodeDeliveryController = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId); IntegrationDeliveryController integrationDeliveryController = IntegrationDeliveryController.getIntegrationDeliveryController( siteNodeId, languageId, contentId); TemplateController templateController = getTemplateController( dbWrapper, siteNodeId, languageId, contentId, new FakeHttpServletRequest(), (InfoGluePrincipal) principal, false, browserBean, nodeDeliveryController, integrationDeliveryController); DeliveryContext deliveryContext = DeliveryContext.getDeliveryContext(/*(InfoGluePrincipal)this.principal*/ ); // deliveryContext.setRepositoryName(repositoryName); deliveryContext.setSiteNodeId(siteNodeId); deliveryContext.setContentId(contentId); deliveryContext.setLanguageId(languageId); deliveryContext.setPageKey("" + System.currentTimeMillis()); // deliveryContext.setSession(new Session(fakeHttpServletSession)); // deliveryContext.setInfoGlueAbstractAction(null); deliveryContext.setHttpServletRequest(fakeHttpServletRequest); deliveryContext.setHttpServletResponse(fakeHttpServletResponse); templateController.setDeliveryContext(deliveryContext); // We don't want a page cache entry to be created deliveryContext.setDisablePageCache(true); SiteNodeVO siteNodeVO = templateController.getSiteNode(siteNodeId); SiteNodeVO rootSiteNodeVO = templateController.getRepositoryRootSiteNode(siteNodeVO.getRepositoryId()); recurseSiteNodeTree( rootSiteNodeVO.getId(), languageId, templateController, principal /*, dbWrapper*/, 1, 0); List templates = ContentController.getContentController() .getContentVOWithContentTypeDefinition("HTMLTemplate", dbWrapper.getDatabase()); Iterator templatesIterator = templates.iterator(); { ContentVO template = (ContentVO) templatesIterator.next(); String templateString = templateController.getContentAttribute(template.getId(), languageId, "Template", true); } RepositoryVO repository = RepositoryDeliveryController.getRepositoryDeliveryController() .getMasterRepository(dbWrapper.getDatabase()); RepositoryDeliveryController.getRepositoryDeliveryController() .getRepositoryVOListFromServerName( dbWrapper.getDatabase(), "localhost", "8080", repository.getName()); logger.info("recache stopped.."); }
private void recurseSiteNodeTree( Integer siteNodeId, Integer languageId, TemplateController templateController, Principal principal /*, DatabaseWrapper dbWrapper*/, int maxLevel, int currentLevel) throws Exception { SiteNode siteNode = SiteNodeController.getController() .getSiteNodeWithId(siteNodeId, templateController.getDatabase(), true); SiteNodeVO siteNodeVO = templateController.getSiteNode(siteNodeId); templateController.getContentAttribute( siteNodeVO.getMetaInfoContentId(), languageId, "Title", true); templateController.getContentAttribute( siteNodeVO.getMetaInfoContentId(), languageId, "NavigationTitle", true); templateController.getContentAttribute( siteNodeVO.getMetaInfoContentId(), languageId, "NiceURIName", true); templateController.getContentAttribute( siteNodeVO.getMetaInfoContentId(), languageId, "Description", true); templateController.getContentAttribute( siteNodeVO.getMetaInfoContentId(), languageId, "ComponentStructure", true); List childPages = templateController.getChildPages(siteNodeId); templateController.getRepositoryRootSiteNode(siteNodeVO.getRepositoryId()); templateController.getParentSiteNode(siteNodeVO.getId()); Collection childSiteNodes = siteNode.getChildSiteNodes(); /* List childSiteNodeIds = new ArrayList(); Iterator childSiteNodesIterator = childSiteNodes.iterator(); while(childSiteNodesIterator.hasNext()) { SiteNode childSiteNode = (SiteNode)childSiteNodesIterator.next(); childSiteNodeIds.add(childSiteNode.getSiteNodeId()); } templateController.commitDatabase(); Iterator childSiteNodeIdsIterator = childSiteNodeIds.iterator(); while(childSiteNodeIdsIterator.hasNext()) { Integer childSiteNodeId = (Integer)childSiteNodeIdsIterator.next(); recurseSiteNodeTree(childSiteNodeId, languageId, templateController, principal); } */ Iterator childSiteNodesIterator = childSiteNodes.iterator(); while (childSiteNodesIterator.hasNext()) { SiteNode childSiteNode = (SiteNode) childSiteNodesIterator.next(); if (maxLevel > currentLevel) recurseSiteNodeTree( childSiteNode.getId(), languageId, templateController, principal, maxLevel, currentLevel + 1); } Repository repository = RepositoryController.getController() .getRepositoryWithId(siteNodeVO.getRepositoryId(), templateController.getDatabase()); Collection languages = repository.getRepositoryLanguages(); Iterator languagesIterator = languages.iterator(); while (languagesIterator.hasNext()) { RepositoryLanguage repositoryLanguage = (RepositoryLanguage) languagesIterator.next(); LanguageDeliveryController.getLanguageDeliveryController() .getLanguageIfSiteNodeSupportsIt( templateController.getDatabase(), repositoryLanguage.getLanguage().getId(), siteNodeId); } Integer contentId = new Integer(-1); FakeHttpSession fakeHttpServletSession = new FakeHttpSession(); FakeHttpServletResponse fakeHttpServletResponse = new FakeHttpServletResponse(); FakeHttpServletRequest fakeHttpServletRequest = new FakeHttpServletRequest(); fakeHttpServletRequest.setParameter("siteNodeId", "" + siteNodeId); fakeHttpServletRequest.setParameter("languageId", "" + languageId); fakeHttpServletRequest.setParameter("contentId", "" + contentId); fakeHttpServletRequest.setRequestURI("ViewPage.action"); fakeHttpServletRequest.setAttribute("siteNodeId", "" + siteNodeId); fakeHttpServletRequest.setAttribute("languageId", "" + languageId); fakeHttpServletRequest.setAttribute("contentId", "" + contentId); fakeHttpServletRequest.setServletContext(DeliverContextListener.getServletContext()); BrowserBean browserBean = new BrowserBean(); // this.browserBean.setRequest(getRequest()); NodeDeliveryController nodeDeliveryController = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId); IntegrationDeliveryController integrationDeliveryController = IntegrationDeliveryController.getIntegrationDeliveryController( siteNodeId, languageId, contentId); TemplateController subTemplateController = getTemplateController( templateController.getDatabaseWrapper(), siteNodeId, languageId, contentId, new FakeHttpServletRequest(), (InfoGluePrincipal) principal, false, browserBean, nodeDeliveryController, integrationDeliveryController); DeliveryContext deliveryContext = DeliveryContext.getDeliveryContext(/*(InfoGluePrincipal)this.principal*/ ); // deliveryContext.setRepositoryName(repositoryName); deliveryContext.setSiteNodeId(siteNodeId); deliveryContext.setContentId(contentId); deliveryContext.setLanguageId(languageId); deliveryContext.setPageKey("" + System.currentTimeMillis()); // deliveryContext.setSession(new Session(fakeHttpServletSession)); // deliveryContext.setInfoGlueAbstractAction(null); deliveryContext.setHttpServletRequest(fakeHttpServletRequest); deliveryContext.setHttpServletResponse(fakeHttpServletResponse); subTemplateController.setDeliveryContext(deliveryContext); // We don't want a page cache entry to be created deliveryContext.setDisablePageCache(true); SiteNodeVO rootSiteNodeVO = templateController.getRepositoryRootSiteNode(siteNodeVO.getRepositoryId()); String pagePath = subTemplateController.getCurrentPagePath(); CacheController.cacheObject("newPagePathCache", deliveryContext.getPageKey(), pagePath); }
@Override public View getView(int position, View convertView, ViewGroup parent) { // declare a new holder holder = new ViewHolder(); // create inflater LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // get rowView from inflater View rowView = null; rowView = inflater.inflate(R.layout.comment_view_row, parent, false); // set all the elements in the custom comment row holder.textViewTitle = (TextView) rowView.findViewById(R.id.textViewTitle); holder.textViewDate = (TextView) rowView.findViewById(R.id.textViewDate); holder.textViewUser = (TextView) rowView.findViewById(R.id.textViewUser); holder.textViewFavCount = (TextView) rowView.findViewById(R.id.textViewFavCount); holder.textViewReplyCount = (TextView) rowView.findViewById(R.id.textViewReplyCount); holder.buttonView = (Button) rowView.findViewById(R.id.buttonView); holder.buttonReply = (Button) rowView.findViewById(R.id.buttonReply); holder.buttonFav = (Button) rowView.findViewById(R.id.buttonFav); holder.buttonSave = (Button) rowView.findViewById(R.id.buttonSave); holder.textViewFavorited = (TextView) rowView.findViewById(R.id.textViewFavorited); holder.textViewSaved = (TextView) rowView.findViewById(R.id.textViewSaved); // set text of textviews holder.textViewTitle.setText(commentList.get(position).getTitle()); holder.textViewDate.setText(commentList.get(position).dateDisplay()); holder.textViewUser.setPaintFlags( holder.textViewUser.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); holder.textViewUser.setText(commentList.get(position).getCommenter().getName()); holder.textViewFavCount.setText( "Favs: " + Integer.toString(commentList.get(position).getFavoriteCount())); holder.textViewReplyCount.setText( "Replies: " + Integer.toString(commentList.get(position).getReplyCount())); // set visibility if comment is in favorites if (favoriteController.inFav(commentList.get(position))) { holder.textViewFavorited.setVisibility(View.VISIBLE); } // set visibility if comment is in cache if (cacheController.inCache(commentList.get(position))) { holder.textViewSaved.setVisibility(View.VISIBLE); } // set onclick listeners for buttons and the tag for position holder.buttonView.setOnClickListener(viewBtnClick); holder.buttonView.setTag(position); holder.buttonReply.setOnClickListener(replyBtnClick); holder.buttonReply.setTag(position); holder.buttonFav.setOnClickListener(favBtnClick); holder.buttonFav.setTag(position); holder.buttonSave.setOnClickListener(saveBtnClick); holder.buttonSave.setTag(position); holder.textViewUser.setTag(position); holder.textViewUser.setOnClickListener(profileBtnClick); // set the holder rowView.setTag(holder); return rowView; }
public void onClick(View v) { final int i = (Integer) v.getTag(); Comment currentComment = commentList.get(i); cacheController.addToCache(context, currentComment); notifyDataSetChanged(); }
private int getCacheSize() { final CacheController<Object, Object> cache = controlCacheDispatcher.getCacheController(CacheType.RECORD_ID); return cache != null ? cache.size() : 0; }