Code

Opened 3 years ago

Closed 22 months ago

#15269 closed Bug (fixed)

get_cache method should be documented as part of move to CACHES

Reported by: abdelazer@… Owned by: clelland
Component: Documentation Version: master
Severity: Normal Keywords: cache
Cc: django@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

While the move to CACHES is explained in docs/topics/cache.txt, it is not clear that this allows the declaration and access of multiple caches.

An example with more than one (a non-'default') cache should be included.

An explanation of how to use get_cache should be included, perhaps just a minor rewording of the docstring?

    Function to load a cache backend dynamically. This is flexible by design
    to allow different use cases:

    To load a backend with the old URI-based notation::

        cache = get_cache('locmem://')

    To load a backend that is pre-defined in the settings::

        cache = get_cache('default')

    To load a backend with its dotted import path,
    including arbitrary options::

        cache = get_cache('django.core.cache.backends.memcached.MemcachedCache', **{
            'LOCATION': '127.0.0.1:11211', 'TIMEOUT': 30,
        })

Attachments (0)

Change History (10)

comment:1 Changed 3 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 3 years ago by lrekucki

  • Severity set to Normal
  • Type set to Bug

comment:3 Changed 3 years ago by aaugustin

  • Easy pickings unset

I think this ticket understates the problem.

Contrary to what the release notes for 1.3 say, the fact that Django supports several caches is not documented at all.

The syntax of settings.CACHES suggests that several caches could be defined, by analogy with settings.DATABASES, but there is nothing about how to use them.

comment:4 follow-up: Changed 3 years ago by jedie

  • Cc django@… added
  • UI/UX unset

Before making get_cache() "public" it should IMHO changed a little bit. Because try this:

cache = get_cache('not_existing_cache')

You will get a strange traceback:

  File "./django/core/cache/__init__.py", line 173, in get_cache
    backend, location, params = parse_backend_conf(backend, **kwargs)
  File "./django/core/cache/__init__.py", line 131, in parse_backend_conf
    mod_path, cls_name = backend.rsplit('.', 1)
ValueError: need more than 1 value to unpack

Should i open a new ticket for this?

comment:5 in reply to: ↑ 4 ; follow-up: Changed 3 years ago by jezdez

Replying to jedie:

Before making get_cache() "public" it should IMHO changed a little bit. Because try this:

cache = get_cache('not_existing_cache')

You will get a strange traceback:

  File "./django/core/cache/__init__.py", line 173, in get_cache
    backend, location, params = parse_backend_conf(backend, **kwargs)
  File "./django/core/cache/__init__.py", line 131, in parse_backend_conf
    mod_path, cls_name = backend.rsplit('.', 1)
ValueError: need more than 1 value to unpack

Should i open a new ticket for this?

Yes, please.

comment:6 in reply to: ↑ 5 Changed 3 years ago by jedie

  • Keywords cache added

Replying to jezdez:

Replying to jedie:

Should i open a new ticket for this?

Yes, please.

done -> #16410

Last edited 3 years ago by jezdez (previous) (diff)

comment:7 Changed 22 months ago by clelland

  • Owner changed from nobody to clelland
  • Status changed from new to assigned

comment:8 Changed 22 months ago by clelland

I've written up a quick paragraph about this; it's available in github at https://github.com/clelland/django/tree/ticket_15269.

Pull request forthcoming.

comment:9 Changed 22 months ago by clelland

  • Has patch set

comment:10 Changed 22 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In e758ecc628bb1d8960d0a59a140a43d7103e89e4:

Merge pull request #386 from clelland/ticket_15269

Fixed #15269 - Added documentation for get_caches function

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.