Skip to content

dmytrokarimov/simple-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Cache

Uses for storing objects with long term of life.
Returns elements from cache or creates new ones if they are not present.
Can be present to store common images, font, etc.

Example of use can be found here:

in this example was created cache for images with auto creating new elements for elements that do not present in cache.

		Cache<ImageIcon> imageIconCache = CacheBuilder.create(ImageIcon.class)
			.addConstructor(String.class, Integer.class, Integer.class)
				.set((params) -> {
					Image image = new ImageIcon(ICONS_PATH + params[0]).getImage();
					Image newimg = image.getScaledInstance((Integer) params[1], (Integer) params[2],  java.awt.Image.SCALE_DEFAULT);
					return new ImageIcon(newimg);
				})
			.addConstructor(String.class)
				.set((params) -> new ImageIcon(ICONS_PATH + params[0]))
			.build();

method addConstructor register specific params set and constructor for this set
here is using of created cache:

	imageIconCache.get(filename, width, height);
	imageIconCache.get(filename);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published