• New Feature
  • Status: Closed
  • 2 Major
  • Resolution: Fixed
  • ehcache-core
  • cdennis
  • Reporter: tlh1005
  • April 13, 2011
  • 0
  • Watchers: 1
  • July 27, 2012
  • June 06, 2011

Description

Because Ehcache does not provide access to the user.name property when setting up the DiskStore path, it is not possible to vary the location of the cache in java.io.tmpdir on UNIX platforms. This is a problem because the first user running Ehcache gets a directory created in tmp that has permissions set for that user. If another user then runs the same application, they do not have access to the cache in tmp because they don’t have permission to do so.

This is not a problem on Windows because the value of java.io.tmpdir varies based on the user, in contrast tmp on UNIX is the same area for all users.

It would be possible to setup a DiskStore path and point to “user.home” and solve this problem, but of course writing to tmp is more desireable.

The ability to do would solve this issue.

Comments

Fiona OShea 2011-04-19

Can you comment on what you think about this? (no fixing or doing:)

Chris Dennis 2011-04-19

Although this particular problem can be worked around at both the OS and JVM levels, this does seem like a reasonable request - while we’re at it we may as well just do full-on property substitution, something like the following should suffice:

private static final Pattern PROPERTY_SUBSTITUTION_PATTERN = Pattern.compile("\\$\\{(.+?)\\}");

private static String substituteProperties(String string) {
    Matcher matcher = PROPERTY_SUBSTITUTION_PATTERN.matcher(string);

    StringBuffer eval = new StringBuffer();
    while (matcher.find()) {
        String substitution = System.getProperty(matcher.group(1));
        if (substitution != null) {
            matcher.appendReplacement(eval, Matcher.quoteReplacement(substitution));
        }
    }
    matcher.appendTail(eval);

    return eval.toString();
}

Chris Dennis 2011-04-19

Incidentally, embedded in the proposed code above is an implied deprecation of the syntax:

<diskStore path="java.io.tmpdir/user.name/myappdir"/>

The new substitution form would be:

<diskStore path="${java.io.tmpdir}/${user.name}/myappdir"/>

We would still support the existing old-format substitutions, but not arbitrary property substitution of using the old syntax.

Fiona OShea 2011-05-09

Assigning back to DRB to review Chris’ comments

Chris Dennis 2011-06-06

I’ve added the ability to do arbitrary property substitution using tokens like “${property-name}”. Support for the four existing substitutions is still in place.