epicserve / django-cache-url

Use Cache URLs in your Django Application
MIT License
18 stars 12 forks source link

Relative file path for "file:" backend? #9

Closed frnhr closed 3 years ago

frnhr commented 3 years ago

Currently:

What I would like to have:

This is in line with how dj-database-url handles sqlite file path:

... This has the effect of four slashes being present for an absolute file path: sqlite:////full/path/to/your/database/file.sqlite.

epicserve commented 3 years ago

@frnhr,

Have a look at https://en.wikipedia.org/wiki/File_URI_scheme.

I believe what we have with the following is correct.

CACHE_URL='file:///my/dir' evaluated to /my/dir

I feel like everything else should probably be invalid. Except if we wanted to support having file://hostname/path/to/, however, I don't think that makes sense when considering Django doesn't seem to have support for different hosts.

frnhr commented 3 years ago

@epicserve You are correct, fair enough.

However, I would like to argue that being able to use relative path here is very useful in many circumstances. If URI doesn't support it, there should be another way of specifying it.

I'm not sure how standard-compliant this is, but I've seen relative paths specified like this: CACHE_URL='file:relative/path' or even CACHE_URL='file:./relative/path'.

Another option, taking a hint from HTML hyperlinks is to omit the schema altogether, just use the naked path CACHE_URL='relative/path'.

A third option that comes to mind is to use a different schema, e.g. "filesystem": CACHE_URL='filesystem://relative/path'

WDYT, is having support for relative paths something you would consider a useful addition to the code, and would any of the three options (or a better one) be acceptable?

epicserve commented 3 years ago

@frnhr,

Have a look at this SO, https://stackoverflow.com/questions/7857416/file-uri-scheme-and-relative-files. The more I think about this, the more I'm not sure relative URL's make sense to me. When you set an environment variable with a relative URL, what is it relative to? The project root or your where your settings file is? Not everyone structures their Django project in the same way, so it seems like you would have to do additional work in your settings to even make this work, right?

CACHES = {'default': django_cache_url.parse('./django_cache')}
CACHES['default']['LOCATION'] = BASE_DIR + CACHES['default']['LOCATION']

IDK, I'm not sure I'm convinced adding relative URL support makes sense. Even in the Django examples they user a full path (e.g. /var/tmp/django_cache). It seems like it would add unnecessary complexity in a way that doesn't have a standard.

epicserve commented 3 years ago

@frnhr,

Closing for now. Let me know if you end up having any additional thoughts.