Posts

Simple in memory cache with plain Java

The following example is simple in memory cache using plain java without using any third party cache libraries. The below implementation shows expiry time based cache eviction and setting maximum cache size. If used with Spring Framework, it is ideal to make this class as DisposableBean to safely execute the shutdown method during application shutdown event. As below @Component public class SimpleCache implements DisposableBean { @Override public void destroy () throws Exception { shutdown(); } } Full implementation: import java.time.Duration ; import java.time.Instant ; import java.util.Comparator ; import java.util.Objects ; import java.util.UUID ; import java.util.concurrent.ConcurrentHashMap ; import java.util.concurrent.Executors ; import java.util.concurrent.ScheduledExecutorService ; import java.util.concurrent.TimeUnit ; public class SimpleCache { public record HeavyObject ( UUID id , String firstName , String lastName ) { } private record CacheValue (...

Unix Essential Commands

This article explains the commands that I have learnt and used in my everyday programming life. nano editor Open a file in nano editor with softwrap and displaying line numbers   nano --softwrap --linenumbers file.txt  chmod command (change a file mode) Symbol and its meaning u -> user g -> group o -> others a -> all r -> read w -> write (and delete) x -> execute (and access directory) + -> add permission - -> take away/remove permission  chmod go-rwx biglist To remove read write and execute permissions on the file/directory biglist for the group and others chmod a+rw biglist To give read and write permissions on the file/directory biglist to all, chmod u+rwx,g+rw,o-rwx test.file Set multiple permission in single command chmod a+rwx directory/* To give permission to all files in a directory chmod -R a+rwx directory/* To give permission to all files/directories in a directory and its sub directories cut command printf "Hello\tworld\nHi\t...