Examples of Cache


Examples of io.druid.client.cache.Cache

            accumulator
        );
      }
    };

    Cache cache = MapCache.create(1024 * 1024);

    String segmentIdentifier = "segment";
    SegmentDescriptor segmentDescriptor = new SegmentDescriptor(new Interval("2011/2012"), "version", 0);

    TopNQueryQueryToolChest toolchest = new TopNQueryQueryToolChest(new TopNQueryConfig());
    DefaultObjectMapper objectMapper = new DefaultObjectMapper();
    CachingQueryRunner runner = new CachingQueryRunner(
        segmentIdentifier,
        segmentDescriptor,
        objectMapper,
        cache,
        toolchest,
        new QueryRunner()
        {
          @Override
          public Sequence run(Query query, Map context)
          {
            return resultSeq;
          }
        },
        new CacheConfig()

    );

    TopNQuery query = builder.build();
    CacheStrategy<Result<TopNResultValue>, Object, TopNQuery> cacheStrategy = toolchest.getCacheStrategy(query);
    Cache.NamedKey cacheKey = CacheUtil.computeSegmentCacheKey(
        segmentIdentifier,
        segmentDescriptor,
        cacheStrategy.computeCacheKey(query)
    );

    HashMap<String,Object> context = new HashMap<String, Object>();
    Sequence res = runner.run(query, context);
    // base sequence is not closed yet
    Assert.assertFalse("sequence must not be closed", closable.isClosed());
    Assert.assertNull("cache must be empty", cache.get(cacheKey));

    ArrayList results = Sequences.toList(res, new ArrayList());
    Assert.assertTrue(closable.isClosed());
    Assert.assertEquals(expectedRes, results);

    Iterable<Result<TopNResultValue>> expectedCacheRes = makeTopNResults(true, objects);

    byte[] cacheValue = cache.get(cacheKey);
    Assert.assertNotNull(cacheValue);

    Function<Object, Result<TopNResultValue>> fn = cacheStrategy.pullFromCache();
    List<Result<TopNResultValue>> cacheResults = Lists.newArrayList(
        Iterators.transform(

Examples of it.marcoberri.mbmeteo.model.Cache

        if (cacheReadEnable) {

            final Query q = ds.find(Cache.class);
            q.filter("cacheKey", cacheKey).filter("servletName", this.getClass().getName());

            final Cache c = (Cache) q.get();

            if (c == null) {
                log.info("cacheKey:" + cacheKey + " on servletName: " + this.getClass().getName() + " not found");
            }

            if (c != null) {
                final GridFSDBFile imageForOutput = MongoConnectionHelper.getGridFS().findOne(new ObjectId(c.getGridId()));
                if (imageForOutput != null) {
                    ds.save(c);

                    try {
                        response.setHeader("Content-Length", "" + imageForOutput.getLength());
                        response.setHeader("Content-Disposition", "inline; filename=\"" + imageForOutput.getFilename() + "\"");
                        final OutputStream out = response.getOutputStream();
                        final InputStream in = imageForOutput.getInputStream();
                        final byte[] content = new byte[(int) imageForOutput.getLength()];
                        in.read(content);
                        out.write(content);
                        in.close();
                        out.close();
                        return;
                    } catch (Exception e) {
                        log.error(e);
                    }

                } else {
                    log.error("file not in db");
                }
            }
        }


        final String formatIn = getFormatIn(period);
        final String formatOut = getFormatOut(period);

        final Query q = ds.createQuery(MapReduceMinMax.class).disableValidation();

        final Date dFrom = DateTimeUtil.getDate("yyyy-MM-dd hh:mm:ss", from);
        final Date dTo = DateTimeUtil.getDate("yyyy-MM-dd hh:mm:ss", to);


        final List<Date> datesIn = getRangeDate(dFrom, dTo);
        final HashSet<String> datesInString = new HashSet<String>();

        for (Date d : datesIn) {
            datesInString.add(DateTimeUtil.dateFormat(formatIn, d));
        }

        if (datesIn != null && !datesIn.isEmpty()) {
            q.filter("_id in", datesInString);
        }
        q.order("_id");

        final List<MapReduceMinMax> mapReduceResult = q.asList();
        final TimeSeries serieMin = new TimeSeries("Min");
        final TimeSeries serieMax = new TimeSeries("Max");

        for (MapReduceMinMax m : mapReduceResult) {
            try {

                final Date tmpDate = DateTimeUtil.getDate(formatIn, m.getId().toString());
                if (tmpDate == null) {
                    continue;
                }

                final Millisecond t = new Millisecond(tmpDate);

                ChartEnumMinMaxHelper chartEnum = ChartEnumMinMaxHelper.getByFieldAndType(field, "min");
                Method method = m.getClass().getMethod(chartEnum.getMethod());
                Number n = (Number) method.invoke(m);
                serieMin.add(t, n);


                chartEnum = ChartEnumMinMaxHelper.getByFieldAndType(field, "max");
                method = m.getClass().getMethod(chartEnum.getMethod());
                n = (Number) method.invoke(m);
                serieMax.add(t, n);


            } catch (IllegalAccessException ex) {
                log.error(ex);
            } catch (IllegalArgumentException ex) {
                log.error(ex);
            } catch (InvocationTargetException ex) {
                log.error(ex);
            } catch (NoSuchMethodException ex) {
                log.error(ex);
            } catch (SecurityException ex) {
                log.error(ex);
            }
        }


        final ChartEnumMinMaxHelper chartData = ChartEnumMinMaxHelper.getByFieldAndType(field, "min");


        final TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(serieMin);
        dataset.addSeries(serieMax);

        final JFreeChart chart = ChartFactory.createTimeSeriesChart("Max/Min", "", chartData.getUm(), dataset, true, false, false);
        final XYPlot plot = (XYPlot) chart.getPlot();
        final DateAxis axis = (DateAxis) plot.getDomainAxis();
        axis.setDateFormatOverride(new SimpleDateFormat(formatOut));

        axis.setVerticalTickLabels(true);

        if (field.toUpperCase().indexOf("PRESSURE") != -1) {
            plot.getRangeAxis().setRange(chartPressureMin, chartPressureMax);
        }

        final File f = File.createTempFile("mbmeteo", ".jpg");
        ChartUtilities.saveChartAsJPEG(f, chart, dimx, dimy);

        try {

            if (cacheWriteEnable) {
                final GridFSInputFile gfsFile = MongoConnectionHelper.getGridFS().createFile(f);
                gfsFile.setFilename(f.getName());
                gfsFile.save();

                final Cache c = new Cache();
                c.setServletName(this.getClass().getName());
                c.setCacheKey(cacheKey);
                c.setGridId(gfsFile.getId().toString());

                ds.save(c);

            }

Examples of javax.cache.Cache

   * Returns object in cache
   * @param key
   * @return
   */
  public static Object get(Object key){
    Cache cache = getCache();
   
    if (cache != null) return cache.get(key);
   
    return null;
  }

Examples of javax.jcache.Cache

   */
    public void loadCache(Collection views)throws CacheException {       
    
       try{     
            Iterator iter = views.iterator();
            Cache cache = factory.getCache();
           while(iter.hasNext()){
         CacheAccess access = null;
               RepositoryView view = (RepositoryView)iter.next();
               BeanDescriptor beanDesc = view.getBeanDescriptor();
               String region = beanDesc.getDatabaseName();
               String group = beanDesc.getRepositoryViewName();
         try{        
             factory.defineRegion(region);
         }
         catch(ObjectExistsException e){
         }
         finally{
               access = factory.getAccess(region);  
         }
         access.defineGroup(group);
                        
           }
       int size = cache.getAttributes().getMemoryCacheSize();
       logger.log(Level.INFO,Messages.format("CacheManager.size",
                       new Integer(size)));                    
       }
       catch(Exception e){
            throw new CacheException(e);

Examples of javax.persistence.Cache

        };

        OperationStepHandler evictAllHandler = new AbstractMetricsHandler() {
            @Override
            void handle(final ModelNode response, final String name, ManagementLookup stats, OperationContext context) {
                Cache secondLevelCache = stats.getEntityManagerFactory().getCache();
                if (secondLevelCache != null) {
                    secondLevelCache.evictAll();
                }
            }
        };
        jpaHibernateRegistration.registerOperationHandler(OPERATION_EVICTALL, evictAllHandler, evictAll);

Examples of javax.util.jcache.Cache

    public void testResetCache() throws Exception {
        CacheAccessFactory factory = CacheAccessFactory.getInstance();
        CacheAttributes catt = CacheAttributes.getDefaultCacheAttributes();
        catt.setLocal();
        catt.setCleanInterval(1);
        Cache cache = factory.getCache(false);
        //
        cache.init(catt);
        //        CacheSweeper.startSweeper executes
        //        within CacheSweeper.getInstance
        //
        CacheSweeper instance = CacheSweeper.getInstance();
       
        cache.close();
        //        CacheSweeper.stopSweeper executes
        //
        cache = factory.getCache(false);
        //
        cache.init(catt);
        CacheSweeper instance2= CacheSweeper.getInstance();
        assertNotSame(instance, instance2);
        //        CacheSweeper.startSweeper does not
        //        execute within CacheSweeper.getInstance
        //        because CacheSweeper instance is not null

Examples of net.paoding.rose.jade.annotation.Cache

        this.realStatement = realStatement;
        this.cacheProvider = cacheProvider;
        StatementMetaData metaData = realStatement.getMetaData();
        SQLType sqlType = metaData.getSQLType();
        cacheDeleteAnnotation = metaData.getMethod().getAnnotation(CacheDelete.class);
        Cache cacheAnnotation = metaData.getMethod().getAnnotation(Cache.class);
        if (sqlType == SQLType.READ) {
            this.cacheAnnotation = cacheAnnotation;
        } else {
            this.cacheAnnotation = null;
            if (cacheAnnotation != null) {

Examples of net.sf.cache4j.Cache

                }
            }

            for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling()) {
                if ((n instanceof Element) && "cache".equalsIgnoreCase(n.getNodeName())) {
                    Cache cache = null;
                    CacheConfig config = null;

                    String id = ((Element)n).getAttribute("id");
                    String desc = ((Element)n).getAttribute("desc");
                    long ttl = getTimeLong(((Element)n).getAttribute("ttl"));

Examples of net.sf.ehcache.Cache

   * @param cache_name
   * @param key
   * @return
   */
  public static Serializable getObjectCached(String cache_name, Serializable key){
    Cache cache = getCache(cache_name);
    if(cache!=null){
      try {
        Element elem = cache.get(key);
        if(elem!=null && !cache.isExpired(elem))
          return elem.getValue();
      } catch (Exception e) {
        log.error("Get cache("+cache_name+") of "+key+" failed.", e);
      }
    }

Examples of net.sf.jsr107cache.Cache

   */
  public void setResult(int x, int y, Date evaluatedAt){
    long elapse = System.currentTimeMillis();
    log.info("[StatisticsManager#setResult()] (x,y)=(" + x +", " + y +")");
    // キャッシュ取得
    Cache cache =
        CacheManager.getInstance().getCache(C_NAME);
    // 集計結果キャッシュを加算
    Summary summary = (Summary) cache.get(C_KEY_SUMMARY);
    log.info("[StatisticsManager#setResult()] got summary from cache: " +
        summary);
    if(summary == null){
      summary = new Summary();
      log.info("[StatisticsManager#setResult()] summary(cache) is null " +
          "/create new summary: " + summary.toString());
    }
   
    summary = Utils.add(x, y, evaluatedAt, summary);
    log.info("[StatisticsManager#setResult()] count up summary: " +
        summary.toString());
    cache.put(C_KEY_SUMMARY, summary);

    // 結果キャッシュを更新
    Results results =
        (Results) cache.get(C_KEY_RESULTS);
    log.info("[StatisticsManager#setResult()] got results from cache: " +
        results);
    if(results == null){
      results = new Results();
      log.info("[StatisticsManager#setResult()] results(cache) is null " +
          "/create new result: " + results.toString());
    }
    results.add(x, y, evaluatedAt);
    log.info("[StatisticsManager#setResult()] count up results: " +
        results.toString());
    cache.put(C_KEY_RESULTS, results);
    log.info("[StatisticsManager#setResult()] update result cache:" +
        results.toString());
    log.info("[StatisticsManager#setResult()] end" +
        (System.currentTimeMillis() - elapse) + "mSec.");
  }
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.