### Cause

Under the hood `System`SquaresR`

is still calling functions in the context `NumberTheory``

.

Partial output of:

```
Needs["GeneralUtilities`"]
PrintDefinitions @ SquaresR
```

```
SquaresR[2, NumberTheory`SquaresRDump`n _ Integer?Positive] :=
Block[{NumberTheory`SquaresRDump`res},
NumberTheory`SquaresRDump`res =
NumberTheory`SquaresRDump`squaresR2[NumberTheory`SquaresRDump`n];
NumberTheory`SquaresRDump`res /; IntegerQ[NumberTheory`SquaresRDump`res]];
```

So all these calls to `SquaresR[2, i]`

and handed off to `NumberTheory`SquaresRDump`squaresR2`

.

```
PrintDefinitions @ NumberTheory`SquaresRDump`squaresR2
```

```
(* contexts omitted *)
squaresR2[0] := 1;
squaresR2[1] := 4;
squaresR2[n_] :=
Block[{res, fact},
fact = FactorInteger[
n]; (res =
If[MemberQ[fact, {p_ /; Mod[p, 4] == 3, _?OddQ}], 0,
4*Times @@ Cases[fact, {p_ /; Mod[p, 4] == 1, a_} :> a + 1]];
squaresR2[n] = res) /; FreeQ[fact, $Failed | FactorInteger]];
squaresR2[___] := $Failed;
```

Note the command `squaresR2[n] = res`

-- this is memoization (caching).

### Solution

We can clear all these memoized values and reload the SquaresR package as follows:

```
ClearAll["NumberTheory`SquaresRDump`*"];
Get[System`Private`$SystemFileDir <>
System`Dump`fixfile["NumberTheory`SquaresR`"] <> "x"]
```

### Commentary

There used to be a more clear distinction between core functions and those in standard packages. Core functions were typically faster, often being at least partially implemented in C, and better integrated with things like `ClearSystemCache`

. Standard package functions were slower, being written in high-level *Mathematica* code, and one would not expect them to be entirely integrated into the system.

In recent versions however standard packages have been deprecated and replaced by functions in the `System``

context. At first one would think these are core functions but in many cases (e.g. `SquaresR`

) they are not. I find this less desirable as one can no longer expect a `System``

function to be fast or well integrated. So in this case I would not consider the "failure" of `ClearSystemCache`

to be a flaw, but rather I consider it a flaw in the recent namespace organization of *Mathematica*.

3At a glance I would consider it a bug or at least oversight that

`ClearSystemCache[]`

does not clear these values. – Mr.Wizard – 2017-01-19T18:45:29.913