GVKun编程网logo

Ehcache 3.7文档—基础篇—GettingStarted(ehcache教程)

15

在这里,我们将给大家分享关于Ehcache3.7文档—基础篇—GettingStarted的知识,让您更了解ehcache教程的本质,同时也会涉及到如何更有效地00-Getting-Started、0

在这里,我们将给大家分享关于Ehcache 3.7文档—基础篇—GettingStarted的知识,让您更了解ehcache教程的本质,同时也会涉及到如何更有效地00-Getting-Started、01 Getting Started 开始、Angular-GettingStarted、com.codahale.metrics.ehcache.InstrumentedEhcache的实例源码的内容。

本文目录一览:

Ehcache 3.7文档—基础篇—GettingStarted(ehcache教程)

Ehcache 3.7文档—基础篇—GettingStarted(ehcache教程)

为了使用Ehcache,你需要配置CacheManager和Cache,有两种方式可以配置java编程配置或者XML文件配置

一. 通过java编程配置

 

CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() (1)
    .withCache("preConfigured",
        CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10))) (2)
    .build(); (3)
cacheManager.init(); (4)

Cache<Long, String> preConfigured =
    cacheManager.getCache("preConfigured", Long.class, String.class); (5)

Cache<Long, String> myCache = cacheManager.createCache("myCache", (6)
    CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)));

myCache.put(1L, "da one!"); (7)
String value = myCache.get(1L);(8) 

cacheManager.removeCache("preConfigured"); (9)

cacheManager.close();(10)

 

(1). 这个静态方法org.ehcache.config.builders.CacheManagerBuilder.newCacheManagerBuilder返回一个新的org.ehcache.config.builders.CacheManagerBuilder实例。

(2). 通过使用CacheManagerBuilder去定义一个名为"preConfigured"的Cache,当cacheManager.build()被调用时这个Cache才会被真正的创建。第一个String参数是Cache的名字,用来从CacheManager中获取Cache的,第二个参数org.ehcache.config.CacheConfiguration是用来配置Cache的,我们使用静态方法newCacheConfigurationBuilder()来创建一个默认的配置。

(3). 最后调用build()返回一个CacheManager实例,但是该实例还没有初始化。

(4). 在使用CacheManager之前需要初始化,有两种方法,一种是调用CacheManager.init(),或者是在调用CacheManagerBuilder.build(boolean init)时使用带参数的方法并且设置成true。

(5). 向CacheManager传入cache name,keyType,valueType来获取一个cache。例如为了获取在第二步定义的cache你需要这样设置alias="preConfigured"keyType=Long.class and valueType=String.class,为了type-safety我们要求两个参数keyType和valueType都传入。如果我们设置的不对,CacheManager会尽早地抛出ClassCastException异常,这样可以防止Cache被随机类型污染。

(6). CacheManager可以创建一个新的Cache,像步骤二那样,他需要传入一个Cache名和一个Cache配置。通过CacheManager.getCache方法可以获取到已经初始化之后的Cache实例。

(7). 现在新添加的cache可以用来储存entries,entries包含了key-value的键值对。put方法的第一个参数是key,第二个参数是value,key和value的类型一定要和CacheConfiguration中定义的一样,除此之外这个cache中的key一定是唯一的,并且只能对应一个value。

(8). 通过cache.get(key)获取value,这个方法只有一个参数key,并且返回这个key关联的value,如果这个key没有关联的value那么就返回null.

(9). 我们可以使用CacheManager.removeCache(String)删除一个给定的cache,CacheManager不仅会删除对Cache的引用,而且还会关闭该Cache,那么Cache会释放本地占用的临时资源如(memory)。Cache的引用也将不可用了。

(10). 为了释放所有的临时资源(memory,threads),CacheManager给Cache实例提供了管理方法,你必须调用CacheManager.close()方法,他会依次的关闭所有存在的Cache实例。

 

下面给出针对上面代码的一个简短版本,主要涉及三个重要的事情

try(CacheManager cacheManager = newCacheManagerBuilder() (1)
  .withCache("preConfigured", newCacheConfigurationBuilder(Long.class, String.class, heap(10))) (2)
  .build(true)) { (3)

  // Same code as before [...]
}

 

(1). A CacheManager implements Closeable so can be closed automatically by a try-with-resources. A CacheManager must be closed cleanly. In a finally block, with a try-with-resources or (more frequent for normal applications) in some shutdown hook.

(2). Builders having different names, you can use static imports for all of them.

(3). CacheManager通过build(true)进行了初始化。

 

二. 通过XML进行配置

 

<config
    xmlns:xsi=''http://www.w3.org/2001/XMLSchema-instance''
    xmlns=''http://www.ehcache.org/v3''
    xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd">

  <cache alias="foo"> (1)
    <key-type>java.lang.String</key-type>(2) 
    <value-type>java.lang.String</value-type>(2) 
    <resources>
      <heap unit="entries">20</heap> (3)
      <offheap unit="MB">10</offheap> (4)
    </resources>
  </cache>

  <cache-template name="myDefaults"> (5)
    <key-type>java.lang.Long</key-type>
    <value-type>java.lang.String</value-type>
    <heap unit="entries">200</heap>
  </cache-template>

  <cache alias="bar" uses-template="myDefaults"> (6)
    <key-type>java.lang.Number</key-type>
  </cache>

  <cache alias="simpleCache" uses-template="myDefaults" />(7) 

</config>

(1). 定义cache的名字为foo

(2). foo的key和value类型被定义为String,如果没有指定类型,那么默认为java.lang.Object。

(3). foo在堆中可以存储20个entries

(4). 10M的堆外空间

(5). <cache-template>元素可以让你定义一个配置模板,然后被继承。

(6). bar就是继承名字为"myDefaults"的<cache-template>的一个cache,并且重写了模板中key-type。

(7). simpleCache是另一个继承myDefault的Cache,它完全使用myDefaults中的配置作为自己的配置。

 

三. 解析XML配置

 为了解析XML配置,你可以使用XmlConfiguration类型:

URL myUrl = getClass().getResource("/my-config.xml"); (1)
Configuration xmlConfig = new XmlConfiguration(myUrl); (2)
CacheManager myCacheManager = CacheManagerBuilder.newCacheManager(xmlConfig); (3)

(1). 获取XML文件的url地址。

(2). 通过传入XML文件的url地址,去实例化一个XmlConfiguration。

(3). 使用静态方法CacheManagerBuilder.newCacheManager(xmlConfig)去创建CacheManager实例。

 

 四.创建集群模式的CacheManager

 为了使用Terracotta(收购了Ehcache和Quartz)的集群模式,首先你要以集群存储模式启动Terracotta服务,除此之外为了创建集群模式的CacheManager,你需要提供集群配置如下:

CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
    CacheManagerBuilder.newCacheManagerBuilder() (1)
        .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application")) (2)
            .autoCreate()); (3)
PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true); (4)

cacheManager.close(); (5)

(1). 返回一个CacheManagerBuilder实例

(2). 使用静态方法.cluster(URL),连接了CacheManager和ClusteringStorage,并且该方法返回了集群服务配置的实例,在上面这个例子中提供了一个简单的URI,用来指定在Terracotta服务上的集群存储标识my-application(假设Terracotta这个服务已经在本地的9410端口运行),参数auto-create表示如果如果不存在那么就创建这个集群存储。

(3). Returns a fully initialized cache manager that can be used to create clustered caches.

(4). Auto-create the clustered storage if it doesn''t already exist.

(5). 关闭CacheManager。

 

五. 分层存储

Ehcache 3和之前的版本一样,支持分层模型,允许在较慢的层中存储更多的数据(通常情况下较慢的层存储空间更大)。

这个分层的理念是,支持快速存储的资源很稀缺,所以HotData优先放到该区域。那些访问频率很少的数据被移到慢存储层上。

三层存储结构,堆空间,堆外空间,磁盘空间。

一个使用三层存储的典型例子如下

PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
    .with(CacheManagerBuilder.persistence(new File(getStoragePath(), "myData"))) (1)
    .withCache("threeTieredCache",
        CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
            ResourcePoolsBuilder.newResourcePoolsBuilder()
                .heap(10, EntryUnit.ENTRIES) (2)
                .offheap(1, MemoryUnit.MB) (3)
                .disk(20, MemoryUnit.MB, true)(4) 
            )
    ).build(true);

Cache<Long, String> threeTieredCache = persistentCacheManager.getCache("threeTieredCache", Long.class, String.class);
threeTieredCache.put(1L, "stillAvailableAfterRestart"); (5)

persistentCacheManager.close();

(1). 如果你想使用磁盘存储(像持久化Cache那样),你需要提供一个数据存储的路径给.persistence()静态方法。

(2). 定义一个heap,这块空间是最快速存储的但是空间小。

(3). 定义一个off-heap,这块空间也是快速的但是空间比上面的大。

(4). 定义一个磁盘持久化存储。

(5). 当JVM重启时(假如CacheManager已经关闭了),cache中的数据也是可以获得的。

 

 六. 数据新鲜度

 在Ehcache中,数据的新鲜度由Expiry来控制,下面举例说明如何配置一个time-to-live expirly。

CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
        ResourcePoolsBuilder.heap(100)) (1)
    .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(20))) (2)
    .build();

 

(1). Expiry是在cache级别配置的,所以先定义一个cache配置。

(2). 然后添加一个Expiry,这里使用的是预定义的time-to-live,他需要一个Duration参数。

 

00-Getting-Started

00-Getting-Started

Download Chart.js

You can download the latest version of Chart.js on GitHub or just use these Chart.js CDN links. If you download or clone the repository, you must run gulp build to generate the dist files. Chart.js no longer comes with prebuilt release versions, so an alternative option to downloading the repo is strongly advised.

Installation

npm

npm install chart.js --save

bower

bower install chart.js --save

Selecting the Correct Build

Chart.js provides two different builds that are available for your use. The Chart.js and Chart.min.js files include Chart.js and the accompanying color parsing library. If this version is used and you require the use of the time axis, Moment.js will need to be included before Chart.js.

The Chart.bundle.js and Chart.bundle.min.js builds include Moment.js in a single file. This version should be used if you require time axes and want a single file to include, select this version. Do not use this build if your application already includes Moment.js. If you do, Moment.js will be included twice, increasing the page load time and potentially introducing version issues.

Usage

To import Chart.js using an old-school script tag:

<script src="Chart.js"></script>
<script>
    var myChart = new Chart({...})
</script>

To import Chart.js using an awesome module loader:


// Using CommonJS
var Chart = require(''src/chart.js'')
var myChart = new Chart({...})

// ES6
import Chart from ''src/chart.js''
let myChart = new Chart({...})

// Using requirejs
require([''path/to/Chartjs''], function(Chart){
 var myChart = new Chart({...})
})

Creating a Chart

To create a chart, we need to instantiate the Chart class. To do this, we need to pass in the node, jQuery instance, or 2d context of the canvas of where we want to draw the chart. Here''s an example.

<canvas id="myChart" width="400" height="400"></canvas>
// Any of the following formats may be used
var ctx = document.getElementById("myChart");
var ctx = document.getElementById("myChart").getContext("2d");
var ctx = $("#myChart");

Once you have the element or context, you''re ready to instantiate a pre-defined chart-type or create your own!

The following example instantiates a bar chart showing the number of votes for different colors and the y-axis starting at 0.

<canvas id="myChart" width="400" height="400"></canvas>
<script>
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
    type: ''bar'',
    data: {
        labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
        datasets: [{
            label: ''# of Votes'',
            data: [12, 19, 3, 5, 2, 3],
            backgroundColor: [
                ''rgba(255, 99, 132, 0.2)'',
                ''rgba(54, 162, 235, 0.2)'',
                ''rgba(255, 206, 86, 0.2)'',
                ''rgba(75, 192, 192, 0.2)'',
                ''rgba(153, 102, 255, 0.2)'',
                ''rgba(255, 159, 64, 0.2)''
            ],
            borderColor: [
                ''rgba(255,99,132,1)'',
                ''rgba(54, 162, 235, 1)'',
                ''rgba(255, 206, 86, 1)'',
                ''rgba(75, 192, 192, 1)'',
                ''rgba(153, 102, 255, 1)'',
                ''rgba(255, 159, 64, 1)''
            ],
            borderWidth: 1
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                }
            }]
        }
    }
});
</script>

It''s that easy to get started using Chart.js! From here you can explore the many options that can help you customise your charts with scales, tooltips, labels, colors, custom actions, and much more.

There are many examples of Chart.js that are available in the /samples folder of Chart.js.zip that is attatched to every release.

01 Getting Started 开始

01 Getting Started 开始

Getting Started 开始

Install the Go tools
Test your installation
Uninstalling Go
Getting help
 

Download the Go distribution 下载go

Download GoClick here to visit the downloads page   点击这里欢迎来到go语言的下载页面

Official binary distributions are available for the FreeBSD (release 10-STABLE and above), Linux, macOS (10.10 and above), and Windows operating systems and the 32-bit (386) and 64-bit (amd64) x86 processor architectures.

官方二进制分布安装

If a binary distribution is not available for your combination of operating system and architecture, try installing from source or installing gccgo instead of gc.    如果二进制分发不可用于您的操作系统和体系结构的组合, 请尝试从源安装或安装 gccgo 而不是 gc。

System requirements  系统要求

Go binary distributions are available for these supported operating systems and architectures. Please ensure your system meets these requirements before proceeding. If your OS or architecture is not on the list, you may be able to install from source or use gccgo instead.

Operating system Architectures Notes

FreeBSD 10.3 or later amd64, 386 Debian GNU/kFreeBSD not supported
Linux 2.6.23 or later with glibc amd64, 386, arm, arm64,
s390x, ppc64le
CentOS/RHEL 5.x not supported.
Install from source for other libc.
macOS 10.10 or later amd64 use the clang or gcc that comes with Xcode for cgo support
Windows 7, Server 2008R2 or later amd64, 386 use MinGW gcc. No need for cygwin or msys.

A C compiler is required only if you plan to use cgo.
You only need to install the command line tools for Xcode. If you have already installed Xcode 4.3+, you can install it from the Components tab of the Downloads preferences panel.

Install the Go tools  go语言工具安装

If you are upgrading from an older version of Go you must first remove the existing version.

如果从go语言旧版本更新到go语言新的版本,你必须先卸载存在的版本

Linux, macOS, and FreeBSD tarballs

Download the archive and extract it into /usr/local, creating a Go tree in /usr/local/go. For example:

tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz

Choose the archive file appropriate for your installation. For instance, if you are installing Go version 1.2.1 for 64-bit x86 on Linux, the archive you want is called go1.2.1.linux-amd64.tar.gz.

(Typically these commands must be run as root or through sudo.)

Add /usr/local/go/bin to the PATH environment variable. You can do this by adding this line to your /etc/profile (for a system-wide installation) or $HOME/.profile:

export PATH=$PATH:/usr/local/go/bin

Note: changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as source $HOME/.profile.

 

macOS package installer

Download the package file, open it, and follow the prompts to install the Go tools. The package installs the Go distribution to /usr/local/go.

The package should put the /usr/local/go/bin directory in your PATH environment variable. You may need to restart any open Terminal sessions for the change to take effect.

Windows

The Go project provides two installation options for Windows users (besides installing from source): a zip archive that requires you to set some environment variables and an MSI installer that configures your installation automatically.

MSI installer

Open the MSI file and follow the prompts to install the Go tools. By default, the installer puts the Go distribution in c:\Go.

The installer should put the c:\Go\bin directory in your PATH environment variable. You may need to restart any open command prompts for the change to take effect.

Zip archive

Download the zip file and extract it into the directory of your choice (we suggest c:\Go).

If you chose a directory other than c:\Go, you must set the GOROOT environment variable to your chosen path.

Add the bin subdirectory of your Go root (for example, c:\Go\bin) to your PATH environment variable.

Setting environment variables under Windows

Under Windows, you may set environment variables through the "Environment Variables" button on the "Advanced" tab of the "System" control panel. Some versions of Windows provide this control panel through the "Advanced System Settings" option inside the "System" control panel.

Test your installation 测试你是否安装成功

Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.

Create your workspace directory, $HOME/go. (If you''d like to use a different directory, you will need to set the GOPATH environment variable.)

Next, make the directory src/hello inside your workspace, and in that directory create a file named hello.gothat looks like:

package main

import "fmt"

func main() {
	fmt.Printf("hello, world\n")
}

Then build it with the go tool:

$ cd $HOME/go/src/hello
$ go build

The command above will build an executable named hello in the directory alongside your source code. Execute it to see the greeting:

$ ./hello
hello, world

If you see the "hello, world" message then your Go installation is working.

You can run go install to install the binary into your workspace''s bin directory or go clean -i to remove it.

Before rushing off to write Go code please read the How to Write Go Code document, which describes some essential concepts about using the Go tools.

Uninstalling Go 卸载go

To remove an existing Go installation from your system delete the go directory. This is usually /usr/local/gounder Linux, macOS, and FreeBSD or c:\Go under Windows.

You should also remove the Go bin directory from your PATH environment variable. Under Linux and FreeBSD you should edit /etc/profile or $HOME/.profile. If you installed Go with the macOS package then you should remove the /etc/paths.d/go file. Windows users should read the section about setting environment variables under Windows.

Getting help  获得帮助

For help, see the list of Go mailing lists, forums, and places to chat.

Report bugs either by running “go bug”, or manually at the Go issue tracker.

Angular-GettingStarted

Angular-GettingStarted

Angular-GettingStarted 介绍

APM-Start:设置的启动程序文件用于VSCode,WebStorm或其他编辑器。使用它来编写课程代码。(更新为Angular版本8或更高版本)

 

APM-Final:已完成的文件。使用此选项可查看课程中已完成的解决方案。(更新为Angular版本8或更高版本)

网站地址:http://bit.ly/Angular-GettingStarted

GitHub:https://github.com/DeborahK/Angular-GettingStarted

网站描述:Getting Started课程中使用的Angular应用程序示例

Angular-GettingStarted官方网站

官方网站:http://bit.ly/Angular-GettingStarted

如果觉得小编网站内容还不错,欢迎将小编网站 推荐给程序员好友。

com.codahale.metrics.ehcache.InstrumentedEhcache的实例源码

com.codahale.metrics.ehcache.InstrumentedEhcache的实例源码

项目:buenojo    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,"entity cannot exist without a identifier");

        net.sf.ehcache.Cache cache = cacheManager.getCache(name);
        if (cache != null) {
            cache.getCacheConfiguration().setTimetoLiveSeconds(jHipsterProperties.getCache().getTimetoLiveSeconds());
            net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry,cache);
            cacheManager.replaceCacheWithDecoratedCache(cache,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:BCDS    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",String.class,"16M"));
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,"entity cannot exist without a identifier");

        net.sf.ehcache.Cache cache = cacheManager.getCache(name);
        if (cache != null) {
            cache.getCacheConfiguration().setTimetoLiveSeconds(env.getProperty("cache.timetoLiveSeconds",Long.class,3600L));
            net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:gameofcode    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:blackhole    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:oyd-pia    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:jhipster-ionic    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:angularjs-springboot-bookstore    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:lobbycal    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:mybatis-ehcache-spring    文件:MybatisMetricsEhcacheFactory.java   
@Override
public Cache getCache(String id) {
  if (id == null) {
    throw new IllegalArgumentException("Cache instances require an ID");
  }

  if (!cacheManager.cacheExists(id)) {
    CacheConfiguration temp = null;
    if (cacheConfiguration != null) {
      temp = cacheConfiguration.clone();
    } else {
      // based on defaultCache
      temp = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
    }
    temp.setName(id);
    net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(temp);
    Ehcache instrumentCache = InstrumentedEhcache.instrument(registry,cache);
    cacheManager.addCache(instrumentCache);
  }
  return new EhcacheCache(id,cacheManager.getEhcache(id));
}
项目:nosql-java    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:ServiceCutter    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:spring-boot-angularjs-examples    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:dataviz-jhipster    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:hadoop-on-demand-rest-jhipster    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:jhipster-websocket-example    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:jittrackGTS    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:website    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:bssuite    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:p2p-webtv    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager(ApplicationProperties applicationProperties) {
  log.debug("Starting Ehcache");
  cacheManager = net.sf.ehcache.CacheManager.create();
  cacheManager.getConfiguration().setMaxBytesLocalHeap(applicationProperties.getCache().getEhcache().getMaxBytesLocalHeap());
  log.debug("Registering Ehcache Metrics gauges");
  Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
  for (EntityType<?> entity : entities) {
    String name = entity.getName();
    if (name == null || entity.getJavaType() != null) {
      name = entity.getJavaType().getName();
    }
    Assert.notNull(name,"entity cannot exist without a identifier");

    net.sf.ehcache.Cache cache = cacheManager.getCache(name);
    if (cache != null) {
      cache.getCacheConfiguration().setTimetoLiveSeconds(applicationProperties.getCache().getTimetoLiveSeconds());
      net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry,cache);
      cacheManager.replaceCacheWithDecoratedCache(cache,decoratedCache);
    }
  }
  EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
  ehCacheManager.setCacheManager(cacheManager);
  return ehCacheManager;
}
项目:quartz-hipster-ui    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:lapetiterennes    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:TSMusicBot    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:JQuaternion    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:lightadmin-jhipster    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap","16M"));
    log.debug("Registring Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:iobrew    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:alv-ch-sysinfos.api    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:BikeMan    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap",decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:cevent-app    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap","16M"));
    log.debug("Registring Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {
        String name = entity.getJavaType().getName();
        net.sf.ehcache.Cache cache = cacheManager.getCache(name);
        if (cache != null) {
            cache.getCacheConfiguration().setTimetoLiveSeconds(env.getProperty("cache.timetoLiveSeconds",Integer.class,3600));
            net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:parkingfriends    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap","16M"));
    log.debug("Registring Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if ( name == null ) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:transandalus-backend    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name,decoratedCache);
        }
    }

    // Cache for KML content in KmlService
    Cache kmlCache = new Cache(new net.sf.ehcache.config.CacheConfiguration("kml",0));
    kmlCache.setName("kml");
    kmlCache.getCacheConfiguration().setEternal(true);
    kmlCache.setBootstrapCacheLoader(bootstrapCacheLoader);

    cacheManager.addCache(kmlCache);
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);

    return ehCacheManager;
}
项目:generator-jhipster-stormpath    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");
    Stream.of(cacheManager.getCacheNames()).forEach(name -> {
        net.sf.ehcache.Cache cache = cacheManager.getCache(name);
        cacheManager.replaceCacheWithDecoratedCache(cache,InstrumentedEhcache.instrument(metricRegistry,cache));
    });
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
项目:jhipster-stormpath-example    文件:CacheConfiguration.java   
private void reconfigureCache(String name,JHipsterProperties jHipsterProperties) {
    net.sf.ehcache.Cache cache = cacheManager.getCache(name);
    if (cache != null) {
        cache.getCacheConfiguration().setTimetoLiveSeconds(jHipsterProperties.getCache().getTimetoLiveSeconds());
        net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry,cache);
        cacheManager.replaceCacheWithDecoratedCache(cache,decoratedCache);
    }
}
项目:teamcity-octopus-build-trigger-plugin    文件:CacheManagerImpl.java   
private synchronized Ehcache getCache(CacheNames cacheName) throws InvalidCacheConfigurationException {
    if (caches.containsKey(cacheName))
        return caches.get(cacheName);
    Cache rawCache = ehCacheManager.getCache(cacheName.name());
    if (rawCache == null)
        throw new InvalidCacheConfigurationException(cacheName);
    Ehcache instrumentedCache = InstrumentedEhcache.instrument(metricRegistry,rawCache);

    caches.put(cacheName,instrumentedCache);
    return instrumentedCache;
}
项目:MLDS    文件:CacheConfiguration.java   
@Bean
public CacheManager cacheManager() {
    if (cacheManager != null) {
        log.debug("Skipping creation of EHcache manager - already exists");
    } else {
     log.debug("Starting Ehcache");
     net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
     net.sf.ehcache.config.CacheConfiguration cacheConfiguration = new net.sf.ehcache.config.CacheConfiguration().maxElementsInMemory(1600);
     config.setDefaultCacheConfiguration(cacheConfiguration);
     cacheManager = net.sf.ehcache.CacheManager.create(config);
     log.debug("Registring Ehcache Metrics gauges");
     Set<EntityType<?>> entities = entityManager.getmetamodel().getEntities();
     for (EntityType<?> entity : entities) {

         String name = entity.getName();
         if (name == null || entity.getJavaType() != null) {
             name = entity.getJavaType().getName();
         }
         Assert.notNull(name,"entity cannot exist without a identifier");

         net.sf.ehcache.Cache cache = cacheManager.getCache(name);
         if (cache != null) {
             cache.getCacheConfiguration().setTimetoLiveSeconds(env.getProperty("cache.timetoLiveSeconds",3600));
             net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry,cache);
             cacheManager.replaceCacheWithDecoratedCache(cache,decoratedCache);
         }
     }
     ehCacheManager = new EhCacheCacheManager();
     ehCacheManager.setCacheManager(cacheManager);
    }
    return ehCacheManager;
}
项目:mica2    文件:CacheConfiguration.java   
@Bean
public CacheManager springCacheManager() {
  log.debug("Starting Spring Cache");
  net.sf.ehcache.CacheManager cacheManager = cacheManagerFactory().getobject();
  EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
  ehCacheManager.setCacheManager(cacheManager);
  String[] cacheNames = cacheManager.getCacheNames();
  for (String cacheName : cacheNames) {
    Cache cache = cacheManager.getCache(cacheName);
    cacheManager.replaceCacheWithDecoratedCache(cache,cache));
  }
  return ehCacheManager;
}

今天的关于Ehcache 3.7文档—基础篇—GettingStartedehcache教程的分享已经结束,谢谢您的关注,如果想了解更多关于00-Getting-Started、01 Getting Started 开始、Angular-GettingStarted、com.codahale.metrics.ehcache.InstrumentedEhcache的实例源码的相关知识,请在本站进行查询。

本文标签: