Clear website cache in V4

Hi,
I’m using ERPNext: v4.20.0 and Frappe Framework: v4.14.3.

I’m doing some changes in the website templates, for example in navbar_link.html in
/home/erpnext/frappe-bench/apps/frappe/frappe/templates/includes

The problem is the JINJA templates remain cached on a random basis.

My question is how can I clear the cache?
It seems that the next day the cache is cleared somehow but I have yet to confirm this,
also this is introduces a delay in the development life-cycle.

I already tried the following:

  • restarting the machine
  • restarting bench with bench restart
  • clearing browser cache
  • logging in and out
  • different users
  • different browsers

Note: any method of clearing the cache would be appreciated, except updating or upgrading since it opens another can of worms.

Hi Alex_Andrei,

Activate frappe’s virtual environment, select particular site using frappe --use site_name and execute following commands,

frappe --clear_web
frappe --clear_cache
frappe -build_sitemap

Also you can use frappe --help to get other framework related commands and their meaning.

Regards,

Hi Saurabh,
it seems I don’t have this command installed
erpnext@erpnext-vm:~/frappe-bench/apps/frappe$ frappe --help
-bash: frappe: command not found

L.E: I have found the frappe binary here
/home/erpnext/frappe-bench/env/bin/frappe

OK. got it, found this

/home/erpnext/frappe-bench/sites/currentsite.txt

and ran the command successfully from this directory
/home/erpnext/frappe-bench
like this
/home/erpnext/frappe-bench/env/bin/frappe --use erpnext.erpnext-vm --clear_cache --clear_web

But the file is still cached.

Where are the cache files or cache data? I will delete myself.

Thanks!

My one line command was not doing anything, so I followed the instructions, which gave me errors.

/home/erpnext/frappe-bench/env/bin/frappe --use erpnext.erpnext-vm - no error

/home/erpnext/frappe-bench/env/bin/frappe --clear_cache
Traceback (most recent call last):
File “/home/erpnext/frappe-bench/env/bin/frappe”, line 9, in
load_entry_point(‘frappe==4.0.0’, ‘console_scripts’, ‘frappe’)()
File “/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py”, line 53, in main
return run(fn, parsed_args)
File “/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py”, line 83, in run
out = globals().get(fn)(**args)
File “/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py”, line 67, in new_fn
return fn(*args, **new_kwargs)
File “/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py”, line 559, in clear_cache
frappe.clear_cache()
File “/home/erpnext/frappe-bench/apps/frappe/frappe/init.py”, line 287, in clear_cache
frappe.sessions.clear_cache()
File “/home/erpnext/frappe-bench/apps/frappe/frappe/sessions.py”, line 49, in clear_cache
for sess in frappe.db.sql(“”“select user, sid from tabSessions”“”, as_dict=1):
File “/home/erpnext/frappe-bench/apps/frappe/frappe/database.py”, line 83, in sql
self.connect()
File “/home/erpnext/frappe-bench/apps/frappe/frappe/database.py”, line 50, in connect
use_unicode=True, charset=‘utf8’)
File “/home/erpnext/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/init.py”, line 81, in Connect
return Connection(*args, **kwargs)
File “/home/erpnext/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 193, in init
super(Connection, self).init(*args, **kwargs2)
TypeError: connect() argument 2 must be string, not None

/home/erpnext/frappe-bench/env/bin/frappe --clear_web
Traceback (most recent call last):
File “/home/erpnext/frappe-bench/env/bin/frappe”, line 9, in
load_entry_point(‘frappe==4.0.0’, ‘console_scripts’, ‘frappe’)()
File “/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py”, line 53, in main
return run(fn, parsed_args)
File “/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py”, line 83, in run
out = globals().get(fn)(**args)
File “/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py”, line 67, in new_fn
return fn(*args, **new_kwargs)
File “/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py”, line 567, in clear_web
frappe.website.render.clear_cache()
File “/home/erpnext/frappe-bench/apps/frappe/frappe/website/render.py”, line 172, in clear_cache
clear_sitemap()
File “/home/erpnext/frappe-bench/apps/frappe/frappe/website/router.py”, line 90, in clear_sitemap
for p in get_pages():
File “/home/erpnext/frappe-bench/apps/frappe/frappe/website/router.py”, line 124, in get_pages
pages = frappe.cache().get_value(“website_pages")
File “/home/erpnext/frappe-bench/apps/frappe/frappe/memc.py”, line 19, in get_value
val = self.get(self.n(key))
File “/home/erpnext/frappe-bench/apps/frappe/frappe/memc.py”, line 10, in n
return (frappe.conf.db_name + “:” + key.replace(" ", "
”)).encode(‘utf-8’)
TypeError: unsupported operand type(s) for +: ‘NoneType’ and ‘unicode’

Hi Alex,

Have you activated virtual environment? If not, then activate it using following way,

goto /home/erpnext/frappe-bench, activate frappe’s virtual environment using source ./env/bin/activate

then goto sites, cd sites

execute
frappe --use sitename
frappe --clear_web
frappe --clear_cache
frappe -build_sitemap

Regards,

Hi Saurabh,
I executed the commands, everything went fine, no errors but the cache is still not cleared fully.

If I refresh the page a couple of times I do get the changes though and then randomly they go away and come back.

Thanks!

Bit of a blast from the past but this is still exactly the problem I have (on current master).

I use and develop custom Jinja functions and filters quite a bit for a customized website app.

On my ‘development server’ (i.e. laptop) it all works OK (with a bit of prodding occasionally), but when I upload to the production server (which I think is actually running in development mode although I could be wrong) it doesn’t clear a cache somewhere.

I use bench build, bench --site SITE clear-cache and bench --site SITE clear-website-cache but these don’t appear to work.

I get erratic failures - each time you reload the page sometimes it works, sometimes it doesn’t. It often doesn’t work immediately after working. Presumably due to some worker threads with a cached version of the Jinja template. I even get ‘server error’ tracebacks which have the line number and exception from the cached version, but when displaying the code line in question gets the line from the new version (so the traceback is inconsistent).

How do you clear the Jinja template caches? :slight_smile: if such a thing is actually possible in Frappe?

Hi Andrew,

To make a suggestion why not start a new thread say how do I clear Jinja template caches?

Be sure to refer to this one, and note the version you are running, so you can draw attention since v4 is rather dated.

This sounds like a case to sift through the code…

Hey, have you got anysolution for this yet?